Skip to content

Commit 3cbf594

Browse files
committed
Deprecate image2wbmp()
According to https://wiki.php.net/rfc/image2wbmp, we deprecate `image2wbmp()`, rename the `$threshold` parameter to `$foreground`, and remove superfluous code.
1 parent 6032390 commit 3cbf594

File tree

4 files changed

+29
-60
lines changed

4 files changed

+29
-60
lines changed

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ readline:
135135
4. Deprecated Functionality
136136
========================================
137137

138+
GD:
139+
. image2wbmp() has been deprecated.
140+
138141
Intl:
139142
. Usage of the Normalizer::NONE form throws a deprecation warning, if PHP is linked with ICU >= 56.
140143

ext/gd/gd.c

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ static void _php_image_create_from(INTERNAL_FUNCTION_PARAMETERS, int image_type,
135135
static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char *tn, void (*func_p)());
136136
static int _php_image_type(char data[12]);
137137
static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type);
138-
static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold);
139138

140139
/* {{{ arginfo */
141140
ZEND_BEGIN_ARG_INFO(arginfo_gd_info, 0)
@@ -764,7 +763,7 @@ ZEND_END_ARG_INFO()
764763
ZEND_BEGIN_ARG_INFO_EX(arginfo_image2wbmp, 0, 0, 1)
765764
ZEND_ARG_INFO(0, im)
766765
ZEND_ARG_INFO(0, filename)
767-
ZEND_ARG_INFO(0, threshold)
766+
ZEND_ARG_INFO(0, foreground)
768767
ZEND_END_ARG_INFO()
769768

770769
#if defined(HAVE_GD_JPG)
@@ -1000,7 +999,7 @@ static const zend_function_entry gd_functions[] = {
1000999
#if defined(HAVE_GD_PNG)
10011000
PHP_DEP_FE(png2wbmp, arginfo_png2wbmp)
10021001
#endif
1003-
PHP_FE(image2wbmp, arginfo_image2wbmp)
1002+
PHP_DEP_FE(image2wbmp, arginfo_image2wbmp)
10041003
PHP_FE(imagelayereffect, arginfo_imagelayereffect)
10051004
PHP_FE(imagexbm, arginfo_imagexbm)
10061005

@@ -2600,7 +2599,7 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char
26002599
int argc = ZEND_NUM_ARGS();
26012600
int q = -1, i, t = 1;
26022601

2603-
/* The quality parameter for Wbmp stands for the threshold when called from image2wbmp() */
2602+
/* The quality parameter for Wbmp stands for the foreground when called from image2wbmp() */
26042603
/* When called from imagewbmp() the quality parameter stands for the foreground color. Default: black. */
26052604
/* The quality parameter for gd2 stands for chunk size */
26062605

@@ -4073,11 +4072,11 @@ static void php_imagettftext_common(INTERNAL_FUNCTION_PARAMETERS, int mode, int
40734072
/* }}} */
40744073
#endif /* ENABLE_GD_TTF */
40754074

4076-
/* {{{ proto bool image2wbmp(resource im [, string filename [, int threshold]])
4075+
/* {{{ proto bool image2wbmp(resource im [, string filename [, int foreground]])
40774076
Output WBMP image to browser or file */
40784077
PHP_FUNCTION(image2wbmp)
40794078
{
4080-
_php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", _php_image_bw_convert);
4079+
_php_image_output(INTERNAL_FUNCTION_PARAM_PASSTHRU, PHP_GDIMG_CONVERT_WBM, "WBMP", NULL);
40814080
}
40824081
/* }}} */
40834082

@@ -4101,59 +4100,6 @@ PHP_FUNCTION(png2wbmp)
41014100
/* }}} */
41024101
#endif
41034102

4104-
/* {{{ _php_image_bw_convert
4105-
* It converts a gd Image to bw using a threshold value */
4106-
static void _php_image_bw_convert(gdImagePtr im_org, gdIOCtx *out, int threshold)
4107-
{
4108-
gdImagePtr im_dest;
4109-
int white, black;
4110-
int color, color_org, median;
4111-
int dest_height = gdImageSY(im_org);
4112-
int dest_width = gdImageSX(im_org);
4113-
int x, y;
4114-
4115-
im_dest = gdImageCreate(dest_width, dest_height);
4116-
if (im_dest == NULL) {
4117-
php_error_docref(NULL, E_WARNING, "Unable to allocate temporary buffer");
4118-
return;
4119-
}
4120-
4121-
white = gdImageColorAllocate(im_dest, 255, 255, 255);
4122-
if (white == -1) {
4123-
php_error_docref(NULL, E_WARNING, "Unable to allocate the colors for the destination buffer");
4124-
return;
4125-
}
4126-
4127-
black = gdImageColorAllocate(im_dest, 0, 0, 0);
4128-
if (black == -1) {
4129-
php_error_docref(NULL, E_WARNING, "Unable to allocate the colors for the destination buffer");
4130-
return;
4131-
}
4132-
4133-
if (im_org->trueColor) {
4134-
if (!gdImageTrueColorToPalette(im_org, 1, 256)) {
4135-
php_error_docref(NULL, E_WARNING, "Unable to convert to palette");
4136-
return;
4137-
}
4138-
}
4139-
4140-
for (y = 0; y < dest_height; y++) {
4141-
for (x = 0; x < dest_width; x++) {
4142-
color_org = gdImageGetPixel(im_org, x, y);
4143-
median = (im_org->red[color_org] + im_org->green[color_org] + im_org->blue[color_org]) / 3;
4144-
if (median < threshold) {
4145-
color = black;
4146-
} else {
4147-
color = white;
4148-
}
4149-
gdImageSetPixel (im_dest, x, y, color);
4150-
}
4151-
}
4152-
gdImageWBMPCtx (im_dest, black, out);
4153-
4154-
}
4155-
/* }}} */
4156-
41574103
/* {{{ _php_image_convert
41584104
* _php_image_convert converts jpeg/png images to wbmp and resizes them as needed */
41594105
static void _php_image_convert(INTERNAL_FUNCTION_PARAMETERS, int image_type )

ext/gd/gd_ctx.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ static void _php_image_output_ctx(INTERNAL_FUNCTION_PARAMETERS, int image_type,
9595
php_stream *stream;
9696
int close_stream = 1;
9797

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

ext/gd/tests/image2wbmp_error.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
image2wbmp() is deprecated
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
$im = imagecreate(10, 10);
10+
imagecolorallocate($im, 0, 0, 0);
11+
image2wbmp($im, __DIR__ . '/image2wbmp_error.wbmp');
12+
?>
13+
===DONE===
14+
--CLEAN--
15+
<?php
16+
unlink(__DIR__ . '/image2wbmp_error.wbmp');
17+
?>
18+
--EXPECTF--
19+
Deprecated: Function image2wbmp() is deprecated in %s on line %d
20+
===DONE===

0 commit comments

Comments
 (0)