summaryrefslogtreecommitdiff
path: root/ext/gd/gd.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/gd/gd.c')
-rw-r--r--ext/gd/gd.c116
1 files changed, 75 insertions, 41 deletions
diff --git a/ext/gd/gd.c b/ext/gd/gd.c
index 378881d56..d026b92b6 100644
--- a/ext/gd/gd.c
+++ b/ext/gd/gd.c
@@ -351,6 +351,12 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefrompng, 0)
ZEND_END_ARG_INFO()
#endif
+#ifdef HAVE_GD_WEBP
+ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromwebp, 0)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+#endif
+
#ifdef HAVE_GD_XBM
ZEND_BEGIN_ARG_INFO(arginfo_imagecreatefromxbm, 0)
ZEND_ARG_INFO(0, filename)
@@ -409,6 +415,13 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_imagepng, 0, 0, 1)
ZEND_END_ARG_INFO()
#endif
+#ifdef HAVE_GD_WEBP
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imagewebp, 0, 0, 1)
+ ZEND_ARG_INFO(0, im)
+ ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()
+#endif
+
#ifdef HAVE_GD_JPG
ZEND_BEGIN_ARG_INFO_EX(arginfo_imagejpeg, 0, 0, 1)
ZEND_ARG_INFO(0, im)
@@ -498,12 +511,13 @@ ZEND_BEGIN_ARG_INFO(arginfo_imagecolorexact, 0)
ZEND_ARG_INFO(0, blue)
ZEND_END_ARG_INFO()
-ZEND_BEGIN_ARG_INFO(arginfo_imagecolorset, 0)
+ZEND_BEGIN_ARG_INFO_EX(arginfo_imagecolorset, 0, 0, 5)
ZEND_ARG_INFO(0, im)
ZEND_ARG_INFO(0, color)
ZEND_ARG_INFO(0, red)
ZEND_ARG_INFO(0, green)
ZEND_ARG_INFO(0, blue)
+ ZEND_ARG_INFO(0, alpha)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO(arginfo_imagecolorsforindex, 0)
@@ -945,6 +959,9 @@ const zend_function_entry gd_functions[] = {
#ifdef HAVE_GD_PNG
PHP_FE(imagecreatefrompng, arginfo_imagecreatefrompng)
#endif
+#ifdef HAVE_GD_WEBP
+ PHP_FE(imagecreatefromwebp, arginfo_imagecreatefromwebp)
+#endif
#ifdef HAVE_GD_GIF_READ
PHP_FE(imagecreatefromgif, arginfo_imagecreatefromgif)
#endif
@@ -968,6 +985,9 @@ const zend_function_entry gd_functions[] = {
#ifdef HAVE_GD_PNG
PHP_FE(imagepng, arginfo_imagepng)
#endif
+#ifdef HAVE_GD_WEBP
+ PHP_FE(imagewebp, arginfo_imagewebp)
+#endif
#ifdef HAVE_GD_GIF_CREATE
PHP_FE(imagegif, arginfo_imagegif)
#endif
@@ -1470,7 +1490,7 @@ PHP_FUNCTION(imageloadfont)
return;
}
- stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE | IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
+ stream = php_stream_open_wrapper(file, "rb", IGNORE_PATH | IGNORE_URL_WIN | REPORT_ERRORS, NULL);
if (stream == NULL) {
RETURN_FALSE;
}
@@ -1559,7 +1579,7 @@ PHP_FUNCTION(imageloadfont)
* that overlap with the old fonts (with indices 1-5). The first
* list index given out is always 1.
*/
- ind = 5 + zend_list_insert(font, le_gd_font);
+ ind = 5 + zend_list_insert(font, le_gd_font TSRMLS_CC);
RETURN_LONG(ind);
}
@@ -2422,7 +2442,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
}
}
- stream = php_stream_open_wrapper(file, "rb", ENFORCE_SAFE_MODE|REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
+ stream = php_stream_open_wrapper(file, "rb", REPORT_ERRORS|IGNORE_PATH|IGNORE_URL_WIN, NULL);
if (stream == NULL) {
RETURN_FALSE;
}
@@ -2431,6 +2451,23 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
ioctx_func_p = NULL; /* don't allow sockets without IOCtx */
#endif
+ if (image_type == PHP_GDIMG_TYPE_WEBP) {
+ size_t buff_size;
+ char *buff;
+
+ /* needs to be malloc (persistent) - GD will free() it later */
+ buff_size = php_stream_copy_to_mem(stream, &buff, PHP_STREAM_COPY_ALL, 1);
+ if (!buff_size) {
+ php_error_docref(NULL TSRMLS_CC, E_WARNING,"Cannot read image data");
+ goto out_err;
+ }
+ im = (*ioctx_func_p)(buff_size, buff);
+ if (!im) {
+ goto out_err;
+ }
+ goto register_im;
+ }
+
/* try and avoid allocating a FILE* if the stream is not naturally a FILE* */
if (php_stream_is(stream, PHP_STREAM_IS_STDIO)) {
if (FAILURE == php_stream_cast(stream, PHP_STREAM_AS_STDIO, (void**)&fp, REPORT_ERRORS)) {
@@ -2508,6 +2545,7 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
fflush(fp);
}
+register_im:
if (im) {
ZEND_REGISTER_RESOURCE(return_value, im, le_gd);
php_stream_close(stream);
@@ -2552,6 +2590,16 @@ PHP_FUNCTION(imagecreatefrompng)
/* }}} */
#endif /* HAVE_GD_PNG */
+#ifdef HAVE_GD_WEBP
+/* {{{ proto resource imagecreatefrompng(string filename)
+ Create a new image from PNG file or URL */
+PHP_FUNCTION(imagecreatefromwebp)
+{
+ _php_image_create_from(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "WEBP", gdImageCreateFromWebpPtr, gdImageCreateFromWebpPtr);
+}
+/* }}} */
+#endif /* HAVE_GD_VPX */
+
#ifdef HAVE_GD_XBM
/* {{{ proto resource imagecreatefromxbm(string filename)
Create a new image from XBM file or URL */
@@ -2625,7 +2673,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
/* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
/* The quality parameter for gd2 stands for chunk size */
- if (zend_parse_parameters(argc TSRMLS_CC, "r|sll", &imgind, &file, &file_len, &quality, &type) == FAILURE) {
+ if (zend_parse_parameters(argc TSRMLS_CC, "r|pll", &imgind, &file, &file_len, &quality, &type) == FAILURE) {
return;
}
@@ -2642,9 +2690,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
}
if (argc >= 2 && file_len) {
- if (strlen(file) != file_len) {
- RETURN_FALSE;
- }
PHP_GD_CHECK_OPEN_BASEDIR(fn, "Invalid filename");
fp = VCWD_FOPEN(fn, "wb");
@@ -2776,7 +2821,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
#if HAVE_GD_BUNDLED
PHP_FUNCTION(imagexbm)
{
- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "XBM", gdImageXbmCtx);
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_XBM, "GIF", gdImageXbmCtx);
}
#endif
/* }}} */
@@ -2786,11 +2831,7 @@ PHP_FUNCTION(imagexbm)
Output GIF image to browser or file */
PHP_FUNCTION(imagegif)
{
-#ifdef HAVE_GD_GIF_CTX
_php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGifCtx);
-#else
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_GIF, "GIF", gdImageGif);
-#endif
}
/* }}} */
#endif /* HAVE_GD_GIF_CREATE */
@@ -2800,25 +2841,29 @@ PHP_FUNCTION(imagegif)
Output PNG image to browser or file */
PHP_FUNCTION(imagepng)
{
-#ifdef USE_GD_IOCTX
- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePngCtxEx);
-#else
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "PNG", gdImagePng);
-#endif
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_PNG, "GIF", gdImagePngCtxEx);
}
/* }}} */
#endif /* HAVE_GD_PNG */
+
+#ifdef HAVE_GD_WEBP
+/* {{{ proto bool imagewebp(resource im [, string filename[, quality]] )
+ Output PNG image to browser or file */
+PHP_FUNCTION(imagewebp)
+{
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WEBP, "GIF", gdImageWebpCtx);
+}
+/* }}} */
+#endif /* HAVE_GD_WEBP */
+
+
#ifdef HAVE_GD_JPG
/* {{{ proto bool imagejpeg(resource im [, string filename [, int quality]])
Output JPEG image to browser or file */
PHP_FUNCTION(imagejpeg)
{
-#ifdef USE_GD_IOCTX
- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpegCtx);
-#else
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "JPEG", gdImageJpeg);
-#endif
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_JPG, "GIF", gdImageJpegCtx);
}
/* }}} */
#endif /* HAVE_GD_JPG */
@@ -2828,11 +2873,7 @@ PHP_FUNCTION(imagejpeg)
Output WBMP image to browser or file */
PHP_FUNCTION(imagewbmp)
{
-#ifdef USE_GD_IOCTX
- _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMPCtx);
-#else
- _php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "WBMP", gdImageWBMP);
-#endif
+ _php_image_output_ctx(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_TYPE_WBM, "GIF", gdImageWBMPCtx);
}
/* }}} */
#endif /* HAVE_GD_WBMP */
@@ -3061,11 +3102,11 @@ PHP_FUNCTION(imagecolorexact)
PHP_FUNCTION(imagecolorset)
{
zval *IM;
- long color, red, green, blue;
+ long color, red, green, blue, alpha = 0;
int col;
gdImagePtr im;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &IM, &color, &red, &green, &blue) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll|l", &IM, &color, &red, &green, &blue, &alpha) == FAILURE) {
return;
}
@@ -3077,6 +3118,7 @@ PHP_FUNCTION(imagecolorset)
im->red[col] = red;
im->green[col] = green;
im->blue[col] = blue;
+ im->alpha[col] = alpha;
} else {
RETURN_FALSE;
}
@@ -4096,7 +4138,7 @@ PHP_FUNCTION(imagepscopyfont)
}
nf_ind->extend = 1;
- l_ind = zend_list_insert(nf_ind, le_ps_font);
+ l_ind = zend_list_insert(nf_ind, le_ps_font TSRMLS_CC);
RETURN_LONG(l_ind);
}
*/
@@ -4145,7 +4187,7 @@ PHP_FUNCTION(imagepsencodefont)
RETURN_FALSE;
}
- zend_list_insert(enc_vector, le_ps_enc);
+ zend_list_insert(enc_vector, le_ps_enc TSRMLS_CC);
RETURN_TRUE;
}
@@ -4550,7 +4592,7 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
long ignore_warning;
#endif
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sslll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "pplll", &f_org, &f_org_len, &f_dest, &f_dest_len, &height, &width, &threshold) == FAILURE) {
return;
}
@@ -4560,14 +4602,6 @@ static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )
dest_width = width;
int_threshold = threshold;
- if (strlen(f_org) != f_org_len) {
- RETURN_FALSE;
- }
-
- if (strlen(f_dest) != f_dest_len) {
- RETURN_FALSE;
- }
-
/* Check threshold value */
if (int_threshold < 0 || int_threshold > 8) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid threshold value '%d'", int_threshold);