#include <stdio.h>
#include "gd.h"
#include "gdfontl.h"
#include "gdfonts.h"

int main(int argc, char **argv) 
{
  /* Input and output files */
     FILE *in;
     FILE *out;
   char inname[80] = "demoin.gif";

    /* Input and output images */
    gdImagePtr im_in, im_out;

      /* Brush image */
    gdImagePtr brush;

 /* Color indexes */
    int white;
    int blue;
    int red;
    int green;
    int x,y;


      /* Create output image, x by y pixels. */
	im_out = gdImageCreate(20, 30);

	/* First color allocated is background. */
	white = gdImageColorAllocate(im_out, 255, 255, 255);

	/* Try to load demoin.gif and paste part of it into the
		output image. */

	if (argc > 1) {
	  strcpy(inname,argv[1]);
	}
	in = fopen(inname, "rb");
	if (!in) {
		fprintf(stderr, "Can't load source image; this demo\n");
		fprintf(stderr, "is much more impressive if demoin.gif\n");
		fprintf(stderr, "is available.\n");
		im_in = 0;
	} else {
		im_in = gdImageCreateFromGif(in);
		fclose(in);
		/* Now copy, and magnify as we do so */
		gdImageCopyResized(im_out, im_in, 
		 0, 0, 0, 0, gdImageSX(im_out), gdImageSY(im_out), 
		 gdImageSX(im_in), gdImageSY(im_in));
	}
	
	printf("pixels...\n");
	for (x=0;x<im_out->sx;x++) {
	 for (y=0;y<im_out->sy;y++) {
	  printf("%d ",im_out->pixels[x][y]);
	 }
	 printf("\n");
	}


	out = fopen("demoout.gif", "wb");
	
	/* Write GIF */
	gdImageGif(im_out, out);
	fclose(out);
	gdImageDestroy(im_out);
	if (im_in) {
		gdImageDestroy(im_in);
	}
	return 0;
}

