
/* gtrans.c */
/* Andrew Davison (ad@ratree.psu.ac.th) */
/* January, 1997 */

/* Usage:
      gtrans <gif-file>

   The yellow in the GIF file is made transparent. 
*/
/* Makes use of the gd graphics library, by
   Thomas Boutell and the Quest Protein Database Center
   at Cold Spring Harbor Labs.
   COPYRIGHT 1994,1995 BY THE QUEST PROTEIN DATABASE CENTER
   AT COLD SPRING HARBOR LABS.
*/
/* compilation:
        \gcc -Wall gtrans.c -o gtrans -L/home/ad/gd1.2 -lgd -lm
*/

#include <stdio.h>
#include "/home/ad/gd1.2/gd.h"

#define MAXLEN 120

int main(int argc, char *argv[])
{
  FILE *fp;
  gdImagePtr im;
  int yellow;

  if (argc != 2) {
    fprintf(stderr, "Usage: gtrans <gif-file>\n");
    exit(1);
  }
  if ((fp = fopen(argv[1], "rb")) == NULL) {
    fprintf(stderr, "Cannot read %s\n", argv[1]);
    exit(1);
  }
  im = gdImageCreateFromGif(fp);
  fclose(fp);

  yellow = gdImageColorExact(im, 255, 255, 0);
  if (yellow == -1) {     /* yellow not present in image */
    fprintf(stderr, "No yellow in %s\n", argv[1]);
    exit(1);
  }

  printf("Making yellow in %s transparent\n", argv[1]);
  gdImageColorTransparent(im, yellow);

  if  ((fp = fopen(argv[1], "wb")) == NULL) {
    fprintf(stderr, "Cannot write to %s\n", argv[1]);
    gdImageDestroy(im);
    exit(1);
  }
  gdImageGif(im, fp);
  fclose(fp);
  gdImageDestroy(im);
  return 0;
}


