summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmb@php.net>2015-06-29 01:36:39 +0200
committerChristoph M. Becker <cmb@php.net>2015-07-12 23:05:53 +0200
commit891ff131efb7a6df37299f35a5110b9bae1b6738 (patch)
treea9ffc92e7be85b3046b5f77d2c89adcc1fb82975
parentc0ac51dc07fac16d72a0b05b4dc70e944e66ffd8 (diff)
downloadphp-git-891ff131efb7a6df37299f35a5110b9bae1b6738.tar.gz
Fix #67447: imagecrop() adds a black line when cropping
A simple one-off error: imagecrop)() copied only width-1 and height-1 pixels.
-rw-r--r--ext/gd/libgd/gd_crop.c6
-rw-r--r--ext/gd/tests/bug67447.phpt26
2 files changed, 29 insertions, 3 deletions
diff --git a/ext/gd/libgd/gd_crop.c b/ext/gd/libgd/gd_crop.c
index 84edb5d1f7..8331521446 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 0000000000..2caa49b623
--- /dev/null
+++ b/ext/gd/tests/bug67447.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Bug #67447 (imagecrop() adds a black line when cropping)
+--FILE--
+<?php
+// true color
+$image = imagecreatetruecolor(500, 500);
+$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);
+
+// 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)