/* * gifmom.c - GIF transparency/interlacing hack. * * I originally wrote this to answer my need for a GIF hacking tool in the * early years of the web. I used it to host a GIF hacking website called * "Make It Clear!" that would transfer GIFs from URL and present them back * to the viewer with the changes they requested. It was unique during its * time since it operated on both files as well as redirected I/O. I had * no idea it had stayed alive on the web all these years. * * This and other hacks can be found at: http://oddgeek.info/code/hacks/ * * This software is covered by the GNU Public License. Original code and * comments are intact. * */ /* * Version Information * * 1.0 2005.05.27 * * Added new comments. Will clean up code later. Please don't hate * me because my code was ugly back then. * * 1.0b 1995.04.19 * * First public release. Code ugly but functional. * * primordial ooze * * Got sick and tired of trying to transparentify and interlace my * web GIFs with a lot of effort. So I looked around and found the * GD library. I hacked together a tool, and once I saw that it * might be useful to others I made it more presentable and hosted * it as part of MotherSoft (MotherSoft is a whole other story). * */ /* gifmom - version 1.0b (c)1995 Jason A. Dour & The University of Louisville Free for distribution, copying, editing, and hacking under the GNU public license. See file 'gnu.public.license.2.0' for specific information. This software comes with no guarantees implicit or implied, and the author(s) of this software cannot be held responsible for loss, damage, acts of god(s), large amounts of small rodentia, deafness, plague, baldness, or nose-bleeds occurring as a direct -- or indirect -- result of the use of 'gifmom.' This software is to be used for imaging, peace, love, and spreading genuine feelings of well being. All other uses are denounced by the author(s). By using this software, you agree to absolutely nothing other than to never try to guess the reasons as to why it is called 'gifmom', nor start any rumors about said reasons. Love, Peace, Gerbils, & Hair Grease, Jason A. Dour */ /* Define the location of the text file of RGB values. [Default is the UNIX X11 location.] */ #define RGB "/usr/lib/X11/rgb.txt" #define GIFMOM "\ngifmom - version 1.0b - (c)1995 Jason A. Dour and the University of Louisville\n\n" #include "gd.h" #include #include int usage(extend) char *extend; { if ( !strcmp(extend,"-?") || !strcmp(extend,"-h") || !strcmp(extend,"-help") ) { printf(GIFMOM); printf(" Thank you for using gifmom!\n\n"); printf(" gifmom is a GIF utility that will allow you to set image options for\n"); printf("interlacing and transparent backgrounds. It uses the gd library by\n"); printf("Thomas Boutell (boutell@netcom.com) for image alteration.\n\n"); printf(" gifmom will take in an image from an input file, process it according\n"); printf("to your instructions, and -- by default -- it will write it back to the\n"); printf("same file. Specifying an output file overrides this option.\n\n"); printf(" gifmom will show you image information is you specify no options, and\n"); printf("image information and a color index table if verbose mode is set. You\n"); printf("might want to pipe verbose image information to more or less. Output\n"); printf("could be up to 270 lines.\n\n"); printf(" gifmom can also read from stdin and write to stdout. If you read from\n"); printf("stdin, stdout is the default output, along with a quiet mode setting. You\n"); printf("cannot override quiet mode when using stdout as output.\n\n"); printf(" gifmom was written by Jason A. Dour, and is (c)1995 Jason A. Dour and\n"); printf("the University of Louisville. Jason may be reached at:\n"); printf(" jadour01@homer.louisville.edu\n\n"); printf(" For the most recent version of gifmom, browse on over to:\n"); printf(" http://www.louisville.edu/public/jadour01/mothersoft/\n\n"); printf("Thanks for your support! -- Jason A. Dour -- April 16th, 1995\n\n"); } else { fprintf(stderr,GIFMOM); fprintf(stderr,"USAGE : gifmom [-h] [-i|+i] [-t #|+t] [-v|-q] [-o [|-]] [|-]\n\n"); fprintf(stderr,"-h Extended help. Pipe it to more/less...\n"); fprintf(stderr,"-i Turn interlacing on.\n"); fprintf(stderr,"+i Turn interlacing off.\n"); fprintf(stderr,"-t # Turn color at index # transparent.\n"); fprintf(stderr,"+t Turn transparent color off.\n"); fprintf(stderr,"-v Verbose output.\n"); fprintf(stderr,"-q Quiet mode. No output. Overrides -v.\n"); fprintf(stderr,"-o Output new image to . Default is input file.\n\n"); }; exit(1); }; int system_error(error) char *error; { fprintf(stderr,"\nERROR! : "); fprintf(stderr,error); fprintf(stderr,"\n"); usage(error); return 1; }; int main(argc,argv) int argc; char *argv[]; { FILE *infile, *outfile; gdImagePtr image = 0; char *output; int loop = 0, index, verbose = 0, other = 0, quiet = 0; if ( argc < 2 ) usage(argv[argc-1]); if ( (argc == 2) && (!strcmp(argv[argc-1],"-h")) ) usage(argv[argc-1]); if ( (argc == 2) && (!strcmp(argv[argc-1],"-help")) ) usage(argv[argc-1]); if ( (argc == 2) && (!strcmp(argv[argc-1],"-?")) ) usage(argv[argc-1]); if ( !strcmp(argv[argc-1],"-") ) { infile = stdin; if ( !infile ) system_error("Cannot open stdin for reading!"); image = gdImageCreateFromGif(infile); fclose(infile); } else { infile = fopen(argv[argc-1],"rb"); if ( !infile ) system_error("Cannot open input file for reading!"); image = gdImageCreateFromGif(infile); fclose(infile); }; if ( argc != 2 ) { for ( loop=1; loop < argc-1; loop++ ) { if ( !strcmp(argv[loop],"+i") ) gdImageInterlace(image,0); else if ( !strcmp(argv[loop],"-i") ) gdImageInterlace(image,1); else if ( !strcmp(argv[loop],"-o") ) { other = 1; loop++; output = argv[loop]; if ( strcmp(argv[loop],"-" ) ) outfile = fopen(argv[loop],"wb"); else { quiet = 1; outfile = stdout; }; if ( !outfile ) system_error("Cannot open output file for writing!"); } else if ( !strcmp(argv[loop],"-t") ) { loop++; index = atoi(argv[loop]); if ( (index >= 0) && (index <= (gdImageColorsTotal(image)-1)) ) { gdImageColorTransparent(image,index); } else system_error("'%d' is outside image color range!",index); } else if ( !strcmp(argv[loop],"+t") ) gdImageColorTransparent(image,-1); else if ( !strcmp(argv[loop],"-v") ) verbose = 1; else if ( !strcmp(argv[loop],"-q") ) quiet = 1; else system_error("Invalid argument!"); }; }; if (!other) { output = argv[argc-1]; if ( strcmp(argv[argc-1],"-") ) outfile = fopen("gifmom.temp.file","wb"); else { quiet = 1; outfile = stdout; }; if (!outfile) system_error("Cannot open temporary output file for writing!"); gdImageGif(image,outfile); if ( strcmp(argv[argc-1],"-") ) fclose(outfile); unlink(argv[argc-1]); rename("gifmom.temp.file",argv[argc-1]); } else { gdImageGif(image,outfile); fclose(outfile); }; if (!quiet) { printf("%s",GIFMOM); printf("Input File : %s\n",argv[argc-1]); printf("Output File : %s\n",output); printf("Image Width : %d\n",gdImageSX(image)); printf("Image Height : %d\n",gdImageSY(image)); printf("# of colors : %d\n",gdImageColorsTotal(image)); printf("Transparent? : "); if ( gdImageGetTransparent(image) >= 0 ) printf("Yes, at index %d.\n",gdImageGetTransparent(image)); else printf("No\n"); printf("Interlaced? : "); if ( gdImageGetInterlaced(image) ) printf("Yes\n\n"); else printf("No\n\n"); if (verbose) { printf("Index Red Green Blue\n"); printf("----------------------------\n"); for (loop=0; loop < gdImageColorsTotal(image); loop++) { printf("%-10d%-6d%-8d%-5d",loop,gdImageRed(image,loop),gdImageGreen(image,loop),gdImageBlue(image,loop)); if ( gdImageGetTransparent(image) == loop ) printf("<--- Transparent Color\n"); else printf("\n"); }; printf("\n"); }; }; if (image) gdImageDestroy(image); return 0; };