Example #1
0
int main()
{
	gdImagePtr im;
	int black;
	FILE *outFile;
	gdIOCtx *out;
	off_t length;

	/* create the test image */
	im = gdImageCreate(11, 11);
	gdImageColorAllocate(im, 255, 255, 255);
	black = gdImageColorAllocate(im, 0, 0, 0);
	gdImageArc(im, 5, 5, 10, 10, 0, 360, black);

	/* write the file to disk, note the file length and delete the file */
	outFile = gdTestTempFp();
	out = gdNewFileCtx(outFile);
	gdTestAssert(out != NULL);
	gdImageXbmCtx(im, "github_bug_170.xbm", 1, out);
	out->gd_free(out);
	length = ftello(outFile);
	fclose(outFile);

	gdImageDestroy(im);

	gdTestAssertMsg(length == 250, "expected to write 250 bytes; %jd bytes written", (intmax_t) length);
	return gdNumFailures();
}
Example #2
0
/*
  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);
}
Example #3
0
BGD_DECLARE(void) gdImageJpeg(gdImagePtr im, FILE *outFile, int quality)
{
	gdIOCtx *out = gdNewFileCtx(outFile);
	if (out == NULL) return;
	gdImageJpegCtx(im, out, quality);
	out->gd_free(out);
}
Example #4
0
void
gdImageGd (gdImagePtr im, FILE * outFile)
{
  gdIOCtx *out = gdNewFileCtx (outFile);
  _gdImageGd (im, out);
  out->free (out);
}
Example #5
0
BGD_DECLARE(void) gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
{
  gdIOCtx *out = gdNewFileCtx (outFile);
  if (out == NULL) return;
  _gdImageGd2 (im, out, cs, fmt);
  out->gd_free (out);
}
Example #6
0
/* gdImageWBMP
 */
BGD_DECLARE(void) gdImageWBMP(gdImagePtr im, int fg, FILE *outFile)
{
	gdIOCtx *out = gdNewFileCtx(outFile);
	if (out == NULL) return;
	gdImageWBMPCtx(im, fg, out);
	out->gd_free(out);
}
Example #7
0
BGD_DECLARE(void) gdImageGifAnimBegin(gdImagePtr im, FILE *outFile, int GlobalCM, int Loops)
{
	gdIOCtx *out = gdNewFileCtx(outFile);
	if (out == NULL) return;
	gdImageGifAnimBeginCtx(im, out, GlobalCM, Loops);
	out->gd_free(out);
}
Example #8
0
BGD_DECLARE(gdImagePtr) gdImageCreateFromJpeg (FILE * inFile)
{
  gdImagePtr im;
  gdIOCtx *in = gdNewFileCtx (inFile);
  im = gdImageCreateFromJpegCtx (in);
  in->gd_free (in);
  return im;
}
Example #9
0
gdImagePtr gdImageCreateFromPng(FILE *inFile)
{
	gdImagePtr im;
	gdIOCtx *in = gdNewFileCtx(inFile);
	im = gdImageCreateFromPngCtx(in);
	in->free(in);
	return im;
}
Example #10
0
/* gdImageCreateFromWBMP
** ---------------------
*/
gdImagePtr gdImageCreateFromWBMP( FILE *inFile )
{
	gdImagePtr	im;
	gdIOCtx *in = gdNewFileCtx( inFile );
	im = gdImageCreateFromWBMPCtx( in );
	in->free(in);
	return (im);
}
Example #11
0
void gdImageGd2 (gdImagePtr im, FILE * outFile, int cs, int fmt)
{
	gdIOCtx *out = gdNewFileCtx(outFile);

	_gdImageGd2(im, out, cs, fmt);

	out->gd_free(out);
}
Example #12
0
/* gdImageCreateFromWBMP
   ** ---------------------
 */
BGD_DECLARE(gdImagePtr) gdImageCreateFromWBMP (FILE * inFile)
{
  gdImagePtr im;
  gdIOCtx *in = gdNewFileCtx (inFile);
  im = gdImageCreateFromWBMPCtx (in);
  in->gd_free (in);
  return (im);
}
Example #13
0
BGD_DECLARE(gdImagePtr) gdImageCreateFromPng (FILE * inFile)
{
	gdImagePtr im;
	gdIOCtx *in = gdNewFileCtx (inFile);
	if (in == NULL) return NULL;
	im = gdImageCreateFromPngCtx (in);
	in->gd_free (in);
	return im;
}
Example #14
0
gdImagePtr gdImageCreateFromJpegEx (FILE * inFile, int ignore_warning)
{
	gdImagePtr im;
	gdIOCtx *in = gdNewFileCtx(inFile);
	im = gdImageCreateFromJpegCtxEx(in, ignore_warning);
	in->gd_free (in);

	return im;
}
Example #15
0
BGD_DECLARE(void) gdImageGifAnimAdd(gdImagePtr im, FILE *outFile, int LocalCM,
                                    int LeftOfs, int TopOfs, int Delay,
                                    int Disposal, gdImagePtr previm)
{
	gdIOCtx *out = gdNewFileCtx(outFile);
	if (out == NULL) return;
	gdImageGifAnimAddCtx(im, out, LocalCM, LeftOfs, TopOfs, Delay, Disposal, previm);
	out->gd_free(out);
}
Example #16
0
BGD_DECLARE(gdImagePtr) gdImageCreateFromJpegEx(FILE *inFile, int ignore_warning)
{
	gdImagePtr im;
	gdIOCtx *in = gdNewFileCtx(inFile);
	if (in == NULL) return NULL;
	im = gdImageCreateFromJpegCtxEx(in, ignore_warning);
	in->gd_free(in);
	return im;
}
Example #17
0
/*
	Function: gdImageCreateFromTga

	Creates a gdImage from a TGA file

	Parameters:

		infile - Pointer to TGA binary file
 */
BGD_DECLARE(gdImagePtr) gdImageCreateFromTga(FILE *fp)
{
	gdImagePtr image;
	gdIOCtx* in = gdNewFileCtx(fp);
	if (in == NULL) return NULL;
	image = gdImageCreateFromTgaCtx(in);
	in->gd_free( in );
	return image;
}
Example #18
0
gdImagePtr gdImageCreateFromGd2Part(FILE *inFile, int srcx, int srcy, int w, int h)
{
	gdImagePtr	im;
        gdIOCtx   	*in = gdNewFileCtx(inFile);

	im = gdImageCreateFromGd2PartCtx(in, srcx, srcy, w, h);

	in->free(in);

	return im;
}
Example #19
0
gdImagePtr gdImageCreateFromGd2 (FILE * inFile)
{
	gdIOCtx *in = gdNewFileCtx(inFile);
	gdImagePtr im;

	im = gdImageCreateFromGd2Ctx(in);

	in->gd_free(in);

	return im;
}
Example #20
0
BGD_DECLARE(void) gdImageGifAnimEnd(FILE *outFile)
{
#if 1
	putc(';', outFile);
#else
	gdIOCtx *out = gdNewFileCtx(outFile);
	if (out == NULL) return;
	gdImageGifAnimEndCtx(out);
	out->gd_free(out);
#endif
}
Example #21
0
BGD_DECLARE(gdImagePtr) gdImageCreateFromGd2Part (FILE * inFile, int srcx, int srcy, int w, int h)
{
  gdImagePtr im;
  gdIOCtx *in = gdNewFileCtx (inFile);

  if (in == NULL) return NULL;
  im = gdImageCreateFromGd2PartCtx (in, srcx, srcy, w, h);

  in->gd_free (in);

  return im;
}
Example #22
0
/* {{{ _php_image_output_ctx */
static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
{
	zval *imgind;
	char *file = NULL;
	int file_len = 0;
	long quality, basefilter;
	gdImagePtr im;
	FILE *fp = NULL;
	int argc = ZEND_NUM_ARGS();
	int q = -1, i;
	int f = -1;
	gdIOCtx *ctx;

	/* The third (quality) parameter for Wbmp stands for the threshold when called from image2wbmp().
	 * The third (quality) parameter for Wbmp and Xbm stands for the foreground color index when called
	 * from imagey<type>().
	 */

	if (image_type == PHP_GDIMG_TYPE_XBM) {
		if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs!|ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) {
			return;
		}
	} else {
		/* PHP_GDIMG_TYPE_GIF
		 * PHP_GDIMG_TYPE_PNG 
		 * PHP_GDIMG_TYPE_JPG 
		 * PHP_GDIMG_TYPE_WBM */
		if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|s!ll", &imgind, &file, &file_len, &quality, &basefilter) == FAILURE) {
			return;
		}		
	}

	ZEND_FETCH_RESOURCE(im, gdImagePtr, &imgind, -1, "Image", phpi_get_le_gd());

	if (argc > 1) {
		if (argc >= 3) {
			q = quality; /* or colorindex for foreground of BW images (defaults to black) */
			if (argc == 4) {
				f = basefilter;
			}
		}
	}

    if (argc > 1 && file_len) {
		PHP_GD_CHECK_OPEN_BASEDIR(file, "Invalid filename");

		fp = VCWD_FOPEN(file, "wb");
		if (!fp) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing: %s", file, strerror(errno));
			RETURN_FALSE;
		}

		ctx = gdNewFileCtx(fp);
	} else {
		ctx = emalloc(sizeof(gdIOCtx));
		ctx->putC = _php_image_output_putc;
		ctx->putBuf = _php_image_output_putbuf;
		ctx->gd_free = _php_image_output_ctxfree;
	}

	switch(image_type) {
		case PHP_GDIMG_CONVERT_WBM:
			if(q<0||q>255) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
			}
		case PHP_GDIMG_TYPE_JPG:
			(*func_p)(im, ctx, q);
			break;
		case PHP_GDIMG_TYPE_PNG:
			(*func_p)(im, ctx, q, f);
			break;
		case PHP_GDIMG_TYPE_XBM:
		case PHP_GDIMG_TYPE_WBM:
			if (argc < 3) {
				for(i=0; i < gdImageColorsTotal(im); i++) {
					if(!gdImageRed(im, i) && !gdImageGreen(im, i) && !gdImageBlue(im, i)) break;
				}
				q = i;
			}
			if (image_type == PHP_GDIMG_TYPE_XBM) {
				(*func_p)(im, file, q, ctx);
			} else {
				(*func_p)(im, q, ctx);
			}
			break;
		default:
			(*func_p)(im, ctx);
			break;
	}

	ctx->gd_free(ctx);

	if(fp) {
		fflush(fp);
		fclose(fp);
	}

    RETURN_TRUE;
}
Example #23
0
BGD_DECLARE(void) gdImageGd (gdImagePtr im, FILE * outFile)
{
  gdIOCtx *out = gdNewFileCtx (outFile);
  _gdImageGd (im, out);
  out->gd_free (out);
}
Example #24
0
void gdImageGif (gdImagePtr im, FILE * outFile)
{
  gdIOCtx *out = gdNewFileCtx (outFile);
  gdImageGifCtx (im, out);
  out->gd_free (out);
}
Example #25
0
/* gdImageWBMP
   ** -----------
 */
void gdImageWBMP (gdImagePtr im, int fg, FILE * outFile)
{
	gdIOCtx *out = gdNewFileCtx(outFile);
	gdImageWBMPCtx(im, fg, out);
	out->gd_free(out);
}
Example #26
0
void gdImageJpeg (gdImagePtr im, FILE * outFile, int quality)
{
	gdIOCtx *out = gdNewFileCtx (outFile);
	gdImageJpegCtx (im, out, quality);
	out->gd_free (out);
}
Example #27
0
static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) 
{
	zval **imgind, **file, **quality;
	gdImagePtr im;
	char *fn = NULL;
	FILE *fp = NULL;
	int argc = ZEND_NUM_ARGS();
	int q = -1, i;
	gdIOCtx *ctx;

	/* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
	
	if (argc < 1 || argc > 3 || zend_get_parameters_ex(argc, &imgind, &file, &quality) == FAILURE) 
	{
		WRONG_PARAM_COUNT;
	}

	ZEND_FETCH_RESOURCE(im, gdImagePtr, imgind, -1, "Image", phpi_get_le_gd());

	if (argc > 1) {
		convert_to_string_ex(file);
		fn = Z_STRVAL_PP(file);
		if (argc == 3) {
			convert_to_long_ex(quality);
			q = Z_LVAL_PP(quality);
		}
	}

	if ((argc == 2) || (argc > 2 && Z_STRLEN_PP(file))) {
		PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");

		fp = VCWD_FOPEN(fn, "wb");
		if (!fp) {
			php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
			RETURN_FALSE;
		}

		ctx = gdNewFileCtx(fp);
	} else {
		ctx = emalloc(sizeof(gdIOCtx));
		ctx->putC = _php_image_output_putc;
		ctx->putBuf = _php_image_output_putbuf;
#if HAVE_LIBGD204
		ctx->gd_free = _php_image_output_ctxfree;
#else
		ctx->free = _php_image_output_ctxfree;
#endif		

#if APACHE && defined(CHARSET_EBCDIC)
		/* XXX this is unlikely to work any more [email protected] */
		/* This is a binary file already: avoid EBCDIC->ASCII conversion */
		ap_bsetflag(php3_rqst->connection->client, B_EBCDIC2ASCII, 0);
#endif
	}

	switch(image_type) {
		case PHP_GDIMG_CONVERT_WBM:
			if(q<0||q>255) {
				php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'. It must be between 0 and 255", q);
			}
		case PHP_GDIMG_TYPE_JPG:
			(*func_p)(im, ctx, q);
			break;
		case PHP_GDIMG_TYPE_WBM:
			for(i=0; i < gdImageColorsTotal(im); i++) {
				if(gdImageRed(im, i) == 0) break;
			} 
			(*func_p)(im, i, ctx);
			break;
		default:
			(*func_p)(im, ctx);
			break;
	}

#if HAVE_LIBGD204	
	ctx->gd_free(ctx);
#else
	ctx->free(ctx);
#endif		

	if(fp) {
		fflush(fp);
		fclose(fp);
	}
	
    RETURN_TRUE;
}
Example #28
0
epicsShareFunc void gdImageGd (gdImagePtr im, FILE * outFile)
{
  gdIOCtx *out = gdNewFileCtx (outFile);
  _gdImageGd (im, out);
  out->gd_free (out);
}