/* Function: gdImageGif <gdImageGif> outputs the specified image to the specified file in GIF format. The file must be open for binary writing. (Under MSDOS and all versions of Windows, it is important to use "wb" as opposed to simply "w" as the mode when opening the file; under Unix there is no penalty for doing so). <gdImageGif> does not close the file; your code must do so. GIF does not support true color; GIF images can contain a maximum of 256 colors. If the image to be written is a truecolor image, such as those created with gdImageCreateTrueColor or loaded from a JPEG or a truecolor PNG image file, a palette-based temporary image will automatically be created internally using the <gdImageCreatePaletteFromTrueColor> function. The original image pixels are not modified. This conversion produces high quality palettes but does require some CPU time. If you are regularly converting truecolor to palette in this way, you should consider creating your image as a palette-based image in the first place. Variants: <gdImageGifCtx> outputs the image via a <gdIOCtx> struct. <gdImageGifPtr> stores the image in a large array of bytes. Parameters: im - The image to write outFile - The FILE pointer to write the image to. Returns: Nothing Example: > gdImagePtr im; > int black, white; > FILE *out; > // Create the image > im = gdImageCreate(100, 100); > // Allocate background > white = gdImageColorAllocate(im, 255, 255, 255); > // Allocate drawing color > black = gdImageColorAllocate(im, 0, 0, 0); > // Draw rectangle > gdImageRectangle(im, 0, 0, 99, 99, black); > // Open output file in binary mode > out = fopen("rect.gif", "wb"); > // Write GIF > gdImageGif(im, out); > // Close file > fclose(out); > // Destroy image > gdImageDestroy(im); */ BGD_DECLARE(void) gdImageGif(gdImagePtr im, FILE *outFile) { gdIOCtx *out = gdNewFileCtx(outFile); if (out == NULL) return; gdImageGifCtx(im, out); out->gd_free(out); }
/* Function: gdImageGifPtr Identical to <gdImageGif> except that it returns a pointer to a memory area with the GIF data. This memory must be freed by the caller when it is no longer needed. The caller *must* invoke <gdFree>, not _free()_. This is because it is not guaranteed that libgd will use the same implementation of malloc, free, etc. as your proggram. The 'size' parameter receives the total size of the block of memory. Parameters: im - The image to write size - Output: the size of the resulting image. Returns: A pointer to the GIF data or NULL if an error occurred. */ BGD_DECLARE(void *) gdImageGifPtr(gdImagePtr im, int *size) { void *rv; gdIOCtx *out = gdNewDynamicCtx(2048, NULL); if (out == NULL) return NULL; gdImageGifCtx(im, out); rv = gdDPExtractData(out, size); out->gd_free(out); return rv; }
void gdImageGif (gdImagePtr im, FILE * outFile) { gdIOCtx *out = gdNewFileCtx (outFile); gdImageGifCtx (im, out); out->gd_free (out); }