summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2017-08-27 13:53:39 +0200
committerChristoph M. Becker <cmbecker69@gmx.de>2017-08-27 13:53:39 +0200
commit499f5480f1a9b3063097b53592c37329c1d5f6f8 (patch)
treef0d73e88cf9d51071e9364b08ff2171d8763a6f3
parentbe9edd83c2b3119018611e178da0ee55f7b71c28 (diff)
downloadphp-git-499f5480f1a9b3063097b53592c37329c1d5f6f8.tar.gz
Fixed bug #75124 (gdImageGrayScale() may produce colors)
We have to make sure to avoid alpha-blending issues by explicitly switching to `gdEffectReplace` and to restore the old value afterwards. This is a port of <https://github.com/libgd/libgd/commit/a7a7ece>.
-rw-r--r--NEWS3
-rw-r--r--ext/gd/libgd/gd_filter.c7
-rw-r--r--ext/gd/tests/bug75124.phpt31
-rw-r--r--ext/gd/tests/bug75124.pngbin0 -> 2436 bytes
4 files changed, 41 insertions, 0 deletions
diff --git a/NEWS b/NEWS
index edd4e29e54..bd93282df5 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,9 @@ PHP NEWS
- CURL:
. Fixed bug #75093 (OpenSSL support not detected). (Remi)
+- GD:
+ . Fixed bug #75124 (gdImageGrayScale() may produce colors). (cmb)
+
- Intl:
. Fixed bug #75090 (IntlGregorianCalendar doesn't have constants from parent
class). (tpunt)
diff --git a/ext/gd/libgd/gd_filter.c b/ext/gd/libgd/gd_filter.c
index 22a393c126..fc48cd08de 100644
--- a/ext/gd/libgd/gd_filter.c
+++ b/ext/gd/libgd/gd_filter.c
@@ -53,12 +53,17 @@ int gdImageGrayScale(gdImagePtr src)
int new_pxl, pxl;
typedef int (*FuncPtr)(gdImagePtr, int, int);
FuncPtr f;
+ int alpha_blending;
+
f = GET_PIXEL_FUNCTION(src);
if (src==NULL) {
return 0;
}
+ alpha_blending = src->alphaBlendingFlag;
+ gdImageAlphaBlending(src, gdEffectReplace);
+
for (y=0; y<src->sy; ++y) {
for (x=0; x<src->sx; ++x) {
pxl = f (src, x, y);
@@ -75,6 +80,8 @@ int gdImageGrayScale(gdImagePtr src)
gdImageSetPixel (src, x, y, new_pxl);
}
}
+ gdImageAlphaBlending(src, alpha_blending);
+
return 1;
}
diff --git a/ext/gd/tests/bug75124.phpt b/ext/gd/tests/bug75124.phpt
new file mode 100644
index 0000000000..b37afc9785
--- /dev/null
+++ b/ext/gd/tests/bug75124.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #75124 (gdImageGrayScale() may produce colors)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('gd extension not available');
+if (!GD_BUNDLED && version_compare(GD_VERSION, '2.2.5', '<')) {
+ die('skip only for bundled libgd or external libgd >= 2.2.5');
+}
+?>
+--FILE--
+<?php
+$im = imagecreatefrompng(__DIR__ . '/bug75124.png');
+var_dump(imageistruecolor($im));
+imagefilter($im, IMG_FILTER_GRAYSCALE);
+for ($i = 0, $width = imagesx($im); $i < $width; $i ++) {
+ for ($j = 0, $height = imagesy($im); $j < $height; $j++) {
+ $color = imagecolorat($im, $i, $j);
+ $red = ($color >> 16) & 0xff;
+ $green = ($color >> 8) & 0xff;
+ $blue = $color & 0xff;
+ if ($red != $green || $green != $blue) {
+ echo "non grayscale pixel detected\n";
+ break 2;
+ }
+ }
+}
+?>
+===DONE===
+--EXPECT--
+bool(true)
+===DONE===
diff --git a/ext/gd/tests/bug75124.png b/ext/gd/tests/bug75124.png
new file mode 100644
index 0000000000..b5d5d1f4b2
--- /dev/null
+++ b/ext/gd/tests/bug75124.png
Binary files differ