-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
75 lines (50 loc) · 1.86 KB
/
main.c
File metadata and controls
75 lines (50 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Bring in gd library functions */
#include "gd.h"
/* Bring in standard I/O so we can output the PNG to a file */
#include <stdio.h>
int main() {
/* Declare the image */
gdImagePtr im;
/* Declare output files */
FILE *pngout, *jpegout;
/* Declare color indexes */
int red;
int white;
/* Allocate the image: 500 pixels across by 200 pixels tall */
im = gdImageCreate(500, 200);
/* Allocate the color black (red, green and blue all minimum).
Since this is the first color in a new image, it will
be the background color. */
red = gdImageColorAllocate(im, 255, 0, 0);
/* Allocate the color white (red, green and blue all maximum). */
white = gdImageColorAllocate(im, 255, 255, 255);
/* Draw a line from the upper left to the lower right,
using white color index. */
gdImageLine(im, 500, 0, 0, 0, white);
gdImageLine(im, 0, 0, 0, 500, white);
gdImageLine(im, 50, 0, 50, 500, white);
gdImageLine(im, 100, 0, 100, 500, white);
gdImageLine(im, 150, 0, 150, 500, white);
gdImageLine(im, 200, 0, 200, 500, white);
gdImageLine(im, 250, 0, 250, 500, white);
gdImageLine(im, 250, 0, 250, 500, white);
gdImageLine(im, 300, 0, 300, 500, white);
gdImageLine(im, 350, 0, 350, 500, white);
gdImageLine(im, 400, 0, 400, 500, white);
gdImageLine(im, 450, 0, 450, 500, white);
/* Open a file for writing. "wb" means "write binary", important
under MSDOS, harmless under Unix. */
pngout = fopen("test.png", "wb");
/* Do the same for a JPEG-format file. */
jpegout = fopen("test.jpg", "wb");
/* Output the image to the disk file in PNG format. */
gdImagePng(im, pngout);
/* Output the same image in JPEG format, using the default
JPEG quality setting. */
gdImageJpeg(im, jpegout, -1);
/* Close the files. */
fclose(pngout);
fclose(jpegout);
/* Destroy the image in memory. */
gdImageDestroy(im);
}