]> granicus.if.org Git - php/commitdiff
add imagesavealpha wrapper (Jukka Holappa <jukkaho@mail.student.oulu.fi>,
authorPierre Joye <pajoye@php.net>
Wed, 26 Feb 2003 23:22:09 +0000 (23:22 +0000)
committerPierre Joye <pajoye@php.net>
Wed, 26 Feb 2003 23:22:09 +0000 (23:22 +0000)
      2 Pierre-Alain Joye)

ext/gd/gd.c

index cafd37ee3056ae59f93d55d6e9b6d2e2362ed399..2123aa68d4ba21e2195f2949e550afbddd1fcae6 100644 (file)
@@ -20,7 +20,7 @@
 
 /* $Id$ */
 
-/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center, 
+/* gd 1.2 is copyright 1994, 1995, Quest Protein Database Center,
    Cold Spring Harbor Labs. */
 
 /* Note that there is no code from the gd package in this file */
@@ -188,6 +188,7 @@ function_entry gd_functions[] = {
        PHP_FE(imagefilledarc,                                                  NULL)
        PHP_FE(imagefilledellipse,                                              NULL)
        PHP_FE(imagealphablending,                                              NULL)
+       PHP_FE(imagesavealpha,                                                  NULL)
        PHP_FE(imagecolorallocatealpha,                                 NULL)
        PHP_FE(imagecolorresolvealpha,                                  NULL)
        PHP_FE(imagecolorclosestalpha,                                  NULL)
@@ -292,7 +293,7 @@ function_entry gd_functions[] = {
        PHP_FE(imagepsbbox,                                                             NULL)
 #endif
        PHP_FE(imagetypes,                                                              NULL)
-       
+
 #if defined(HAVE_GD_JPG) && defined(HAVE_GD_WBMP)
        PHP_FE(jpeg2wbmp,                                                               NULL)
 #endif
@@ -301,7 +302,7 @@ function_entry gd_functions[] = {
 #endif
 #ifdef HAVE_GD_WBMP
        PHP_FE(image2wbmp,                                                              NULL)
-#endif 
+#endif
 #if HAVE_GD_BUNDLED
        PHP_FE(imagelayereffect,                                                NULL)
        PHP_FE(imagecolormatch,                                                 NULL)
@@ -634,7 +635,7 @@ int gdImageColorResolve(gdImagePtr im, int r, int g, int b)
 
 /* {{{ proto int imageloadfont(string filename)
    Load a new font */
-PHP_FUNCTION(imageloadfont) 
+PHP_FUNCTION(imageloadfont)
 {
        zval **file;
        int hdr_size = sizeof(gdFont) - sizeof(char *);
@@ -662,7 +663,7 @@ PHP_FUNCTION(imageloadfont)
         * byte 8-11:  (int) pixel width of each character
         * byte 12-15: (int) pixel height of each character
         * bytes 16-:  (char) array with character data, one byte per pixel
-        *                    in each character, for a total of 
+        *                    in each character, for a total of
         *                    (nchars*width*height) bytes.
         */
        font = (gdFontPtr)emalloc(sizeof(gdFont));
@@ -744,7 +745,7 @@ PHP_FUNCTION(imagesetstyle)
        stylearr = emalloc(sizeof(int) * zend_hash_num_elements(HASH_OF(*styles)));
 
        zend_hash_internal_pointer_reset_ex(HASH_OF(*styles), &pos);
-               
+
        for (index=0;; zend_hash_move_forward_ex(HASH_OF(*styles), &pos))       {
                zval ** item;
 
@@ -794,7 +795,7 @@ PHP_FUNCTION(imageistruecolor)
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &IM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        RETURN_BOOL(im->trueColor);
@@ -815,7 +816,7 @@ PHP_FUNCTION(imagetruecolortopalette)
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
        convert_to_boolean_ex(dither);
        convert_to_long_ex(ncolors);
-               
+
        gdImageTrueColorToPalette(im, Z_LVAL_PP(dither), Z_LVAL_PP(ncolors));
 
        RETURN_TRUE;
@@ -873,7 +874,7 @@ PHP_FUNCTION(imagesetthickness)
 
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
        convert_to_long_ex(thick);
-               
+
        gdImageSetThickness(im, Z_LVAL_PP(thick));
 
        RETURN_TRUE;
@@ -890,7 +891,7 @@ PHP_FUNCTION(imagefilledellipse)
        if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(cx);
@@ -937,7 +938,7 @@ PHP_FUNCTION(imagefilledarc)
        gdImageFilledArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col), Z_LVAL_PP(style));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto void imagealphablending(resource im, bool on)
    Turn alpha blending mode on or off for the given image */
@@ -952,13 +953,34 @@ PHP_FUNCTION(imagealphablending)
 
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
        convert_to_boolean_ex(blend);
-               
+
        gdImageAlphaBlending(im, Z_LVAL_PP(blend));
 
        RETURN_TRUE;
 }
 /* }}} */
 
+#if HAVE_LIBGD20
+/* {{{ proto void imagesavealpha(resource im, bool on)
+   Include alpha channel to a saved image */
+PHP_FUNCTION(imagesavealpha)
+{
+       zval **IM, **save;
+       gdImagePtr im;
+
+       if (ZEND_NUM_ARGS() != 2 ||     zend_get_parameters_ex(2, &IM, &save) == FAILURE) {
+               ZEND_WRONG_PARAM_COUNT();
+       }
+
+       ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
+       convert_to_boolean_ex(save);
+
+       gdImageSaveAlpha(im, Z_LVAL_PP(save));
+
+       RETURN_TRUE;
+}
+#endif
+
 #if HAVE_GD_BUNDLED
 /* {{{ proto void imagelayereffect(resource im, int effect)
    Set the alpha blending flag to use the bundled libgd layering effects */
@@ -1009,7 +1031,7 @@ PHP_FUNCTION(imagecolorresolvealpha)
        if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
@@ -1031,7 +1053,7 @@ PHP_FUNCTION(imagecolorclosestalpha)
        if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
@@ -1053,14 +1075,14 @@ PHP_FUNCTION(imagecolorexactalpha)
        if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &red, &green, &blue, &alpha) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
        convert_to_long_ex(alpha);
-       
+
        RETURN_LONG(gdImageColorExactAlpha(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue), Z_LVAL_PP(alpha)));
 }
 /* }}} */
@@ -1206,7 +1228,7 @@ PHP_FUNCTION(imagecreate)
    Return the types of images supported in a bitfield - 1=GIF, 2=JPEG, 4=PNG, 8=WBMP, 16=XPM */
 PHP_FUNCTION(imagetypes)
 {
-       int ret=0;      
+       int ret=0;
 #ifdef HAVE_GD_GIF_CREATE
        ret = 1;
 #endif
@@ -1262,15 +1284,15 @@ static int _php_image_type (char data[8])
                                io_ctx->gd_free(io_ctx);
 #else
                                io_ctx->free(io_ctx);
-#endif                                                         
+#endif
                                return PHP_GDIMG_TYPE_WBM;
                        } else {
 #if HAVE_LIBGD204
                                io_ctx->gd_free(io_ctx);
 #else
                                io_ctx->free(io_ctx);
-#endif                                                         
-                       }       
+#endif
+                       }
                }
        }
 #endif
@@ -1279,7 +1301,7 @@ static int _php_image_type (char data[8])
 }
 /* }}} */
 
-#ifdef HAVE_LIBGD15 
+#ifdef HAVE_LIBGD15
 /* {{{ _php_image_create_from_string
  */
 gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioctx_func_p)() TSRMLS_DC)
@@ -1302,7 +1324,7 @@ gdImagePtr _php_image_create_from_string(zval **data, char *tn, gdImagePtr (*ioc
        io_ctx->gd_free(io_ctx);
 #else
        io_ctx->free(io_ctx);
-#endif 
+#endif
        return im;
 }
 /* }}} */
@@ -1319,7 +1341,7 @@ PHP_FUNCTION(imagecreatefromstring)
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &data) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        convert_to_string_ex(data);
        memcpy(sig, Z_STRVAL_PP(data), 8);
 
@@ -1343,7 +1365,7 @@ PHP_FUNCTION(imagecreatefromstring)
                        RETURN_FALSE;
 #endif
                        break;
-                       
+
                case PHP_GDIMG_TYPE_GIF:
 #ifdef HAVE_GD_GIF_READ
                        im = _php_image_create_from_string (data, "GIF", gdImageCreateFromGifCtx TSRMLS_CC);
@@ -1388,7 +1410,7 @@ PHP_FUNCTION(imagecreatefromstring)
 
 /* {{{ _php_image_create_from
  */
-static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)()) 
+static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, gdImagePtr (*func_p)(), gdImagePtr (*ioctx_func_p)())
 {
        zval **file, **srcx, **srcy, **width, **height;
        gdImagePtr im = NULL;
@@ -1396,19 +1418,19 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
        php_stream *stream;
        FILE * fp = NULL;
        int argc=ZEND_NUM_ARGS();
-       
+
        if ((image_type == PHP_GDIMG_TYPE_GD2PART && argc != 5) ||
-               (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) || 
+               (image_type != PHP_GDIMG_TYPE_GD2PART && argc != 1) ||
                zend_get_parameters_ex(argc, &file, &srcx, &srcy, &width, &height) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        convert_to_string_ex(file);
 
        if (argc == 5 && image_type == PHP_GDIMG_TYPE_GD2PART) {
                multi_convert_to_long_ex(4, srcx, srcy, width, height);
        }
-       
+
        fn = Z_STRVAL_PP(file);
 
        stream = php_stream_open_wrapper(fn, "rb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
@@ -1440,7 +1462,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                        php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
                        goto out_err;
                }
-               
+
                io_ctx = gdNewDynamicCtx(buff_size, buff);
                if(!io_ctx) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot allocate GD IO context");
@@ -1455,16 +1477,16 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
                io_ctx->gd_free(io_ctx);
 #else
                io_ctx->free(io_ctx);
-#endif                                                                         
+#endif
 
-#endif         
+#endif
        }
        else    {
                /* try and force the stream to be FILE* */
                if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO | PHP_STREAM_CAST_TRY_HARD, (void**)&fp, REPORT_ERRORS))
                        goto out_err;
        }
-       
+
        if (!im && fp)  {
                switch (image_type) {
                        case PHP_GDIMG_TYPE_GD2PART:
@@ -1585,7 +1607,7 @@ PHP_FUNCTION(imagecreatefromgd2part)
 
 /* {{{ _php_image_output
  */
-static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)()) 
+static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)())
 {
        zval **imgind, **file, **quality, **type;
        gdImagePtr im;
@@ -1628,7 +1650,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to open '%s' for writing", fn);
                        RETURN_FALSE;
                }
-               
+
                switch(image_type) {
                        case PHP_GDIMG_CONVERT_WBM:
                                if(q<0||q>255) {
@@ -1650,7 +1672,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
                                }
                                (*func_p)(im, fp);
                                break;
-#endif                         
+#endif
                        default:
                                if (q == -1) {
                                        q = 128;
@@ -1692,7 +1714,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
                                }
                                (*func_p)(im, tmp);
                                break;
-#endif                         
+#endif
                        default:
                                (*func_p)(im, tmp);
                                break;
@@ -1821,13 +1843,13 @@ PHP_FUNCTION(imagecolorallocate)
        if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
-       
+
        RETURN_LONG(gdImageColorAllocate(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
 }
 /* }}} */
@@ -1843,7 +1865,7 @@ PHP_FUNCTION(imagepalettecopy)
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &dstim, &srcim) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(dst, gdImagePtr, dstim, -1, "Image", le_gd);
        ZEND_FETCH_RESOURCE(src, gdImagePtr, srcim, -1, "Image", le_gd);
 
@@ -1862,7 +1884,7 @@ PHP_FUNCTION(imagecolorat)
        if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &IM, &x, &y) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(x);
@@ -1904,13 +1926,13 @@ PHP_FUNCTION(imagecolorclosest)
        if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
-       
+
        RETURN_LONG(gdImageColorClosest(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
 }
 /* }}} */
@@ -1922,13 +1944,13 @@ PHP_FUNCTION(imagecolorclosesthwb)
 {
        zval **IM, **red, **green, **blue;
        gdImagePtr im;
-       
+
        if (ZEND_NUM_ARGS() != 4 ||     zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
 
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
-       
+
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
@@ -1982,13 +2004,13 @@ PHP_FUNCTION(imagecolorresolve)
        if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
-       
+
        RETURN_LONG(gdImageColorResolve(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
 }
 /* }}} */
@@ -2003,13 +2025,13 @@ PHP_FUNCTION(imagecolorexact)
        if (ZEND_NUM_ARGS() != 4 || zend_get_parameters_ex(4, &IM, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
-       
+
        RETURN_LONG(gdImageColorExact(im, Z_LVAL_PP(red), Z_LVAL_PP(green), Z_LVAL_PP(blue)));
 }
 /* }}} */
@@ -2025,16 +2047,16 @@ PHP_FUNCTION(imagecolorset)
        if (ZEND_NUM_ARGS() != 5 || zend_get_parameters_ex(5, &IM, &color, &red, &green, &blue) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(color);
        convert_to_long_ex(red);
        convert_to_long_ex(green);
        convert_to_long_ex(blue);
-       
+
        col = Z_LVAL_PP(color);
-       
+
        if (col >= 0 && col < gdImageColorsTotal(im)) {
                im->red[col]   = Z_LVAL_PP(red);
                im->green[col] = Z_LVAL_PP(green);
@@ -2056,7 +2078,7 @@ PHP_FUNCTION(imagecolorsforindex)
        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &IM, &index) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(index);
@@ -2069,7 +2091,7 @@ PHP_FUNCTION(imagecolorsforindex)
                add_assoc_long(return_value,"green", gdImageGreen(im,col));
                add_assoc_long(return_value,"blue", gdImageBlue(im,col));
                add_assoc_long(return_value,"alpha", gdImageAlpha(im,col));
-       } 
+       }
 #else
        if (col >= 0 && col < gdImageColorsTotal(im)) {
                array_init(return_value);
@@ -2114,7 +2136,7 @@ PHP_FUNCTION(imagegammacorrect)
                for (y = 0; y < gdImageSY(im); y++)     {
                        for (x = 0; x < gdImageSX(im); x++)     {
                                c = gdImageGetPixel(im, x, y);
-                               gdImageSetPixel(im, x, y, 
+                               gdImageSetPixel(im, x, y,
                                                gdTrueColor(
                                                        (int)((pow((pow((gdTrueColorGetRed(c) / 255.0), input)), 1.0 / output) * 255)+.5),
                                                        (int)((pow((pow((gdTrueColorGetGreen(c) / 255.0), input)), 1.0 / output) * 255)+.5),
@@ -2157,7 +2179,7 @@ PHP_FUNCTION(imagesetpixel)
 
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imageline(int im, int x1, int y1, int x2, int y2, int col)
    Draw a line */
@@ -2181,12 +2203,12 @@ PHP_FUNCTION(imageline)
 #ifdef HAVE_GD_BUNDLED
        if (im->antialias)
                gdImageAALine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
-       else 
-#endif 
+       else
+#endif
                gdImageLine(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagedashedline(int im, int x1, int y1, int x2, int y2, int col)
    Draw a dashed line */
@@ -2234,7 +2256,7 @@ PHP_FUNCTION(imagerectangle)
        gdImageRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagefilledrectangle(int im, int x1, int y1, int x2, int y2, int col)
    Draw a filled rectangle */
@@ -2258,7 +2280,7 @@ PHP_FUNCTION(imagefilledrectangle)
        gdImageFilledRectangle(im, Z_LVAL_PP(x1), Z_LVAL_PP(y1), Z_LVAL_PP(x2), Z_LVAL_PP(y2), Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagearc(int im, int cx, int cy, int w, int h, int s, int e, int col)
    Draw a partial ellipse */
@@ -2291,7 +2313,7 @@ PHP_FUNCTION(imagearc)
        gdImageArc(im, Z_LVAL_PP(cx), Z_LVAL_PP(cy), Z_LVAL_PP(w), Z_LVAL_PP(h), st, e, Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto void imageellipse(resource im, int cx, int cy, int w, int h, int color)
    Draw an ellipse */
@@ -2303,7 +2325,7 @@ PHP_FUNCTION(imageellipse)
        if (ZEND_NUM_ARGS() != 6 || zend_get_parameters_ex(6, &IM, &cx, &cy, &w, &h, &color) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        ZEND_FETCH_RESOURCE(im, gdImagePtr, IM, -1, "Image", le_gd);
 
        convert_to_long_ex(cx);
@@ -2343,7 +2365,7 @@ PHP_FUNCTION(imagefilltoborder)
        gdImageFillToBorder(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(border), Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagefill(int im, int x, int y, int col)
    Flood fill */
@@ -2365,7 +2387,7 @@ PHP_FUNCTION(imagefill)
        gdImageFill(im, Z_LVAL_PP(x), Z_LVAL_PP(y), Z_LVAL_PP(col));
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagecolorstotal(int im)
    Find out the number of colors in an image's palette */
@@ -2382,7 +2404,7 @@ PHP_FUNCTION(imagecolorstotal)
 
        RETURN_LONG(gdImageColorsTotal(im));
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagecolortransparent(int im [, int col])
    Define a color as transparent */
@@ -2415,7 +2437,7 @@ PHP_FUNCTION(imagecolortransparent)
 
        RETURN_LONG(gdImageGetTransparent(im));
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imageinterlace(int im [, int interlace])
    Enable or disable interlace */
@@ -2448,18 +2470,18 @@ PHP_FUNCTION(imageinterlace)
 
        RETURN_LONG(gdImageGetInterlaced(im));
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ php_imagepolygon
    arg = 0  normal polygon
    arg = 1  filled polygon */
 /* im, points, num_points, col */
-static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled) 
+static void php_imagepolygon(INTERNAL_FUNCTION_PARAMETERS, int filled)
 {
        zval **IM, **POINTS, **NPOINTS, **COL;
        pval **var = NULL;
        gdImagePtr im;
-       gdPointPtr points;      
+       gdPointPtr points;
        int npoints, col, nelem, i;
 
        if (ZEND_NUM_ARGS() != 4 ||     zend_get_parameters_ex(4, &IM, &POINTS, &NPOINTS, &COL) == FAILURE) {
@@ -2539,7 +2561,7 @@ static gdFontPtr php_find_gd_font(int size)
        gdFontPtr font;
        int ind_type;
        TSRMLS_FETCH();
-       
+
        switch (size) {
                case 1:
                         font = gdFontTiny;
@@ -2584,7 +2606,7 @@ static void php_imagefontsize(INTERNAL_FUNCTION_PARAMETERS, int arg)
        if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &SIZE) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        convert_to_long_ex(SIZE);
 
        font = php_find_gd_font(Z_LVAL_PP(SIZE));
@@ -2622,7 +2644,7 @@ static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, i
        for (py = y; (py > (y - f->w)); py--) {
                for (px = x; (px < (x + f->h)); px++) {
                        if (f->data[fline + cy * f->w + cx]) {
-                               gdImageSetPixel(im, px, py, color);     
+                               gdImageSetPixel(im, px, py, color);
                        }
                        cy++;
                }
@@ -2638,7 +2660,7 @@ static void php_gdimagecharup(gdImagePtr im, gdFontPtr f, int x, int y, int c, i
  * arg = 2  ImageString
  * arg = 3  ImageStringUp
  */
-static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode) 
+static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
 {
        zval **IM, **SIZE, **X, **Y, **C, **COL;
        gdImagePtr im;
@@ -2704,8 +2726,8 @@ static void php_imagechar(INTERNAL_FUNCTION_PARAMETERS, int mode)
 /* }}} */
 
 /* {{{ proto int imagechar(int im, int font, int x, int y, string c, int col)
-   Draw a character */ 
-PHP_FUNCTION(imagechar) 
+   Draw a character */
+PHP_FUNCTION(imagechar)
 {
        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 0);
 }
@@ -2713,7 +2735,7 @@ PHP_FUNCTION(imagechar)
 
 /* {{{ proto int imagecharup(int im, int font, int x, int y, string c, int col)
    Draw a character rotated 90 degrees counter-clockwise */
-PHP_FUNCTION(imagecharup) 
+PHP_FUNCTION(imagecharup)
 {
        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 1);
 }
@@ -2721,7 +2743,7 @@ PHP_FUNCTION(imagecharup)
 
 /* {{{ proto int imagestring(int im, int font, int x, int y, string str, int col)
    Draw a string horizontally */
-PHP_FUNCTION(imagestring) 
+PHP_FUNCTION(imagestring)
 {
        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 2);
 }
@@ -2729,21 +2751,21 @@ PHP_FUNCTION(imagestring)
 
 /* {{{ proto int imagestringup(int im, int font, int x, int y, string str, int col)
    Draw a string vertically - rotated 90 degrees counter-clockwise */
-PHP_FUNCTION(imagestringup) 
+PHP_FUNCTION(imagestringup)
 {
        php_imagechar(INTERNAL_FUNCTION_PARAM_PASSTHRU, 3);
 }
 /* }}} */
 
 /* {{{ proto int imagecopy(int dst_im, int src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)
-   Copy part of an image */ 
+   Copy part of an image */
 PHP_FUNCTION(imagecopy)
 {
        zval **SIM, **DIM, **SX, **SY, **SW, **SH, **DX, **DY;
        gdImagePtr im_dst, im_src;
        int srcH, srcW, srcY, srcX, dstY, dstX;
 
-       if (ZEND_NUM_ARGS() != 8 ||     
+       if (ZEND_NUM_ARGS() != 8 ||
                zend_get_parameters_ex(8, &DIM, &SIM, &DX, &DY, &SX, &SY, &SW, &SH) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
        }
@@ -2883,7 +2905,7 @@ PHP_FUNCTION(imagecopyresized)
        gdImageCopyResized(im_dst, im_src, dstX, dstY, srcX, srcY, dstW, dstH, srcW, srcH);
        RETURN_TRUE;
 }
-/* }}} */      
+/* }}} */
 
 /* {{{ proto int imagesx(int im)
    Get image width */
@@ -2942,7 +2964,7 @@ PHP_FUNCTION(imagefttext)
        php_imagettftext_common(INTERNAL_FUNCTION_PARAM_PASSTHRU, TTFTEXT_DRAW, 1);
 }
 /* }}} */
-#endif 
+#endif
 
 
 /* {{{ proto array imagettfbbox(int size, int angle, string font_file, string text)
@@ -2979,7 +3001,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
 #if !HAVE_GD_STRINGFTEX
        assert(!extended);
 #endif
-       
+
        argc = ZEND_NUM_ARGS();
 
        if (mode == TTFTEXT_BBOX) {
@@ -3014,12 +3036,12 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
 #if HAVE_GD_STRINGFTEX
                if (EXT)        {
                        /* parse extended info */
-                       
+
                        HashPosition pos;
-                       
+
                        convert_to_array_ex(EXT);
                        memset(&strex, 0, sizeof(strex));
-                       
+
                        /* walk the assoc array */
                        zend_hash_internal_pointer_reset_ex(HASH_OF(*EXT), &pos);
                        do {
@@ -3031,17 +3053,17 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
 
                          if (zend_hash_get_current_data_ex(HASH_OF(*EXT), (void**)&item, &pos) == FAILURE)
                                  continue;
-                               
+
                          if (strcmp("linespacing", key) == 0)  {
                                        convert_to_double_ex(item);
                                        strex.flags |= gdFTEX_LINESPACE;
                                        strex.linespacing = Z_DVAL_PP(item);
                          }
-                         
+
                        } while(zend_hash_move_forward_ex(HASH_OF(*EXT), &pos) == SUCCESS);
                }
 #endif
-               
+
        }
 
        ptsize = Z_DVAL_PP(PTSIZE);
@@ -3082,7 +3104,7 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s", error);
                RETURN_FALSE;
        }
-       
+
        array_init(return_value);
 
        /* return array with the text's bounding box */
@@ -3331,11 +3353,11 @@ PHP_FUNCTION(imagepstext)
        char *str;
        int str_len;
        int argc = ZEND_NUM_ARGS();
-       
+
        if (argc != 8 && argc != 12) {
                ZEND_WRONG_PARAM_COUNT();
        }
-       
+
        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rsrlllll|lldl", &img, &str, &str_len, &fnt, &size, &_fg, &_bg, &x, &y, &space, &width, &angle, &aa_steps) == FAILURE) {
                return;
        }
@@ -3348,7 +3370,7 @@ PHP_FUNCTION(imagepstext)
        if (_fg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
 #else
        if (_fg < 0 || _fg > gdImageColorsTotal(bg_img)) {
-#endif 
+#endif
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Foreground color index %d out of range", _fg);
                RETURN_FALSE;
        }
@@ -3357,11 +3379,11 @@ PHP_FUNCTION(imagepstext)
        if (_bg < 0 || (!gdImageTrueColor(bg_img) && _fg > gdImageColorsTotal(bg_img))) {
 #else
        if (_bg < 0 || _bg > gdImageColorsTotal(bg_img)) {
-#endif 
+#endif
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Background color index %d out of range", _bg);
                RETURN_FALSE;
        }
-       
+
        fg_rd = gdImageRed  (bg_img, _fg);
        fg_gr = gdImageGreen(bg_img, _fg);
        fg_bl = gdImageBlue (bg_img, _fg);
@@ -3415,7 +3437,7 @@ PHP_FUNCTION(imagepstext)
        if (!str_path) {
                if (T1_errno) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "libt1 returned error %d", T1_errno);
-               }       
+               }
                RETURN_FALSE;
        }
 
@@ -3555,7 +3577,7 @@ PHP_FUNCTION(imagepsbbox)
                str_bbox = T1_GetStringBBox(*f_ind, Z_STRVAL_PP(str), Z_STRLEN_PP(str), space, T1_KERNING);
        }
        if (T1_errno) RETURN_FALSE;
-       
+
        array_init(return_value);
        /*
        printf("%d %d %d %d\n", str_bbox.llx, str_bbox.lly, str_bbox.urx, str_bbox.ury);
@@ -3566,7 +3588,7 @@ PHP_FUNCTION(imagepsbbox)
        add_next_index_long(return_value, (int) ceil(((double) str_bbox.ury)*Z_LVAL_PP(sz)/1000));
 }
 /* }}} */
-#endif 
+#endif
 
 #ifdef HAVE_GD_WBMP
 /* {{{ proto int image2wbmp(int im [, string filename [, int threshold]])
@@ -3601,7 +3623,7 @@ PHP_FUNCTION(png2wbmp)
 #ifdef HAVE_GD_WBMP
 /* {{{ _php_image_bw_convert
  * It converts a gd Image to bw using a threshold value */
-static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshold) 
+static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshold)
 {
        gdImagePtr im_dest;
        int white, black;
@@ -3610,7 +3632,7 @@ static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshol
        int dest_width = gdImageSX (im_org);
        int x, y;
        TSRMLS_FETCH();
-       
+
        im_dest = gdImageCreate (dest_width, dest_height);
        if (im_dest == NULL) {
                php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unable to allocate temporary buffer");
@@ -3652,7 +3674,7 @@ static void _php_image_bw_convert( gdImagePtr im_org, gdIOCtx *out, int threshol
 
 /* {{{ _php_image_convert
  * _php_image_convert converts jpeg/png images to wbmp and resizes them as needed  */
-static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type ) 
+static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
 {
        zval **f_org, **f_dest, **height, **width, **threshold;
        gdImagePtr im_org, im_dest, im_tmp;
@@ -3838,7 +3860,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
        fclose(dest);
 
        gdImageDestroy( im_dest );
-       
+
        RETURN_TRUE;
 }
 /* }}} */
@@ -3856,7 +3878,7 @@ static void php_image_filter_negate(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(1, &SIM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
        if ( im_src==NULL ) {
@@ -3875,7 +3897,7 @@ static void php_image_filter_grayscale(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_array_ex(1, &SIM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3895,7 +3917,7 @@ static void php_image_filter_brightness(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=3 || zend_parse_parameters(3 TSRMLS_CC, "zll", &SIM, &tmp, &brightness) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3912,10 +3934,10 @@ static void php_image_filter_contrast(INTERNAL_FUNCTION_PARAMETERS)
        zval *SIM;
        gdImagePtr im_src;
        long contrast, tmp;
-    
+
        if (ZEND_NUM_ARGS()!=3 || zend_parse_parameters(3 TSRMLS_CC, "rll", &SIM, &tmp, &contrast) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3935,7 +3957,7 @@ static void php_image_filter_colorize(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=5 || zend_parse_parameters(5 TSRMLS_CC, "rllll", &SIM, &tmp, &r, &g, &b) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3954,7 +3976,7 @@ static void php_image_filter_edgedetect(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(1, &SIM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3973,7 +3995,7 @@ static void php_image_filter_emboss(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(1, &SIM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -3992,7 +4014,7 @@ static void php_image_filter_gaussian_blur(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(1, &SIM) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -4051,7 +4073,7 @@ static void php_image_filter_smooth(INTERNAL_FUNCTION_PARAMETERS)
 
        if (ZEND_NUM_ARGS()!=3 || zend_parse_parameters(3 TSRMLS_CC, "rld", &SIM, &tmp, &weight) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        ZEND_FETCH_RESOURCE(im_src, gdImagePtr, &SIM, -1, "Image", le_gd);
        if (im_src==NULL) {
@@ -4071,7 +4093,7 @@ PHP_FUNCTION(imagefilter)
 
        typedef void (*image_filter)(INTERNAL_FUNCTION_PARAMETERS);
        long filtertype;
-       image_filter filters[] = 
+       image_filter filters[] =
        {
                php_image_filter_negate ,
                php_image_filter_grayscale,
@@ -4088,7 +4110,7 @@ PHP_FUNCTION(imagefilter)
 
        if (ZEND_NUM_ARGS()<2 || ZEND_NUM_ARGS()>5 || zend_parse_parameters(2 TSRMLS_CC, "rl", &tmp, &filtertype) == FAILURE) {
                ZEND_WRONG_PARAM_COUNT();
-       }       
+       }
 
        if (filtertype>=0 && filtertype<=IMAGE_FILTER_MAX) {
                filters[filtertype](INTERNAL_FUNCTION_PARAM_PASSTHRU);