From 891ff131efb7a6df37299f35a5110b9bae1b6738 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Mon, 29 Jun 2015 01:36:39 +0200 Subject: [PATCH 1/2] Fix #67447: imagecrop() adds a black line when cropping A simple one-off error: imagecrop)() copied only width-1 and height-1 pixels. --- ext/gd/libgd/gd_crop.c | 6 +++--- ext/gd/tests/bug67447.phpt | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 ext/gd/tests/bug67447.phpt diff --git a/ext/gd/libgd/gd_crop.c b/ext/gd/libgd/gd_crop.c index 84edb5d1f7f..83315214465 100644 --- a/ext/gd/libgd/gd_crop.c +++ b/ext/gd/libgd/gd_crop.c @@ -80,14 +80,14 @@ printf("rect->x: %i\nrect->y: %i\nrect->width: %i\nrect->height: %i\n", crop->x, y = crop->y; if (src->trueColor) { unsigned int dst_y = 0; - while (y < (crop->y + (crop->height - 1))) { + while (y < (crop->y + crop->height)) { /* TODO: replace 4 w/byte per channel||pitch once available */ memcpy(dst->tpixels[dst_y++], src->tpixels[y++] + crop->x, crop->width * 4); } } else { int x; - for (y = crop->y; y < (crop->y + (crop->height - 1)); y++) { - for (x = crop->x; x < (crop->x + (crop->width - 1)); x++) { + for (y = crop->y; y < (crop->y + crop->height); y++) { + for (x = crop->x; x < (crop->x + crop->width); x++) { dst->pixels[y - crop->y][x - crop->x] = src->pixels[y][x]; } } diff --git a/ext/gd/tests/bug67447.phpt b/ext/gd/tests/bug67447.phpt new file mode 100644 index 00000000000..2caa49b6239 --- /dev/null +++ b/ext/gd/tests/bug67447.phpt @@ -0,0 +1,26 @@ +--TEST-- +Bug #67447 (imagecrop() adds a black line when cropping) +--FILE-- + 0, 'y' => 0, 'width' => 250, 'height' => 250]); +var_dump(imagecolorat($cropped, 249, 249) === $red); +imagedestroy($image); +imagedestroy($cropped); + +// palette +$image = imagecreate(500, 500); +imagecolorallocate($image, 0, 0, 255); // first palette color = background +$red = imagecolorallocate($image, 255, 0, 0); +imagefill($image, 0, 0, $red); +$cropped = imagecrop($image, ['x' => 0, 'y' => 0, 'width' => 250, 'height' => 250]); +var_dump(imagecolorat($cropped, 249, 249) === $red); +imagedestroy($image); +imagedestroy($cropped); +?> +--EXPECT-- +bool(true) +bool(true) From 591fd4cdc3429931951ec08c7e5edd7af6e1c916 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sun, 12 Jul 2015 23:13:13 +0200 Subject: [PATCH 2/2] updated NEWS --- NEWS | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS b/NEWS index 6d9dd15ae1c..e3a4e0d44a7 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,7 @@ PHP NEWS . Fixed bug #64878 (304 responses return Content-Type header). (cmb) - GD: + . Fixed bug #67447 (imagecrop() add a black line when cropping). (cmb) . Fixed bug #68714 (copy 'n paste error). (cmb) . Fixed bug #66339 (PHP segfaults in imagexbm). (cmb) . Fixed bug #70047 (gd_info() doesn't report WebP support). (cmb)