Skip to content

Commit ff7fd3d

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79676: imagescale adds black border with IMG_BICUBIC
2 parents 09532a1 + 86e1f0e commit ff7fd3d

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ PHP NEWS
2121
- Filter:
2222
. Fixed bug #73527 (Invalid memory access in php_filter_strip). (cmb)
2323

24+
- GD:
25+
. Fixed bug #79676 (imagescale adds black border with IMG_BICUBIC). (cmb)
26+
2427
- OpenSSL:
2528
. Fixed bug #62890 (default_socket_timeout=-1 causes connection to timeout).
2629
(cmb)

ext/gd/libgd/gd_interpolation.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ static inline void _gdScaleRow(gdImagePtr pSrc, unsigned int src_width, gdImage
936936
int *p_dst_row = dst->tpixels[row];
937937
unsigned int x;
938938

939-
for (x = 0; x < dst_width - 1; x++) {
939+
for (x = 0; x < dst_width; x++) {
940940
register unsigned char r = 0, g = 0, b = 0, a = 0;
941941
const int left = contrib->ContribRow[x].Left;
942942
const int right = contrib->ContribRow[x].Right;
@@ -972,7 +972,7 @@ static inline int _gdScaleHoriz(gdImagePtr pSrc, unsigned int src_width, unsigne
972972
return 0;
973973
}
974974
/* Scale each row */
975-
for (u = 0; u < dst_height - 1; u++) {
975+
for (u = 0; u < dst_height; u++) {
976976
_gdScaleRow(pSrc, src_width, pDst, dst_width, u, contrib);
977977
}
978978
_gdContributionsFree (contrib);
@@ -982,7 +982,7 @@ static inline int _gdScaleHoriz(gdImagePtr pSrc, unsigned int src_width, unsigne
982982
static inline void _gdScaleCol (gdImagePtr pSrc, unsigned int src_width, gdImagePtr pRes, unsigned int dst_width, unsigned int dst_height, unsigned int uCol, LineContribType *contrib)
983983
{
984984
unsigned int y;
985-
for (y = 0; y < dst_height - 1; y++) {
985+
for (y = 0; y < dst_height; y++) {
986986
register unsigned char r = 0, g = 0, b = 0, a = 0;
987987
const int iLeft = contrib->ContribRow[y].Left;
988988
const int iRight = contrib->ContribRow[y].Right;
@@ -1019,7 +1019,7 @@ static inline int _gdScaleVert (const gdImagePtr pSrc, const unsigned int src_wi
10191019
return 0;
10201020
}
10211021
/* scale each column */
1022-
for (u = 0; u < dst_width - 1; u++) {
1022+
for (u = 0; u < dst_width; u++) {
10231023
_gdScaleCol(pSrc, src_width, pDst, dst_width, dst_height, u, contrib);
10241024
}
10251025
_gdContributionsFree(contrib);

ext/gd/tests/bug79676.phpt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
Bug #79676 (imagescale adds black border with IMG_BICUBIC)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('gd')) die('skip gd extension not available');
6+
?>
7+
--FILE--
8+
<?php
9+
function test($image, $desc)
10+
{
11+
echo "$desc - Test Result: ",
12+
(imagecolorat($image, imagesx($image) - 1 , imagesy($image) - 1) != 0x000000 ? 'pass' : 'fail'),
13+
PHP_EOL;
14+
}
15+
16+
$size = 32;
17+
$src = imagecreatetruecolor($size, $size);
18+
imagefilledrectangle($src, 0, 0, $size - 1 , $size - 1, 0xff00ff);
19+
20+
test($src, 'No scaling');
21+
test(imagescale($src, $size * 2, $size * 2), 'Scale 200%, default mode');
22+
test(imagescale($src, $size / 2, $size / 2), 'Scale 50%, default mode');
23+
test(imagescale($src, $size * 2, $size * 2, IMG_BICUBIC), 'Scale 200%, IMG_BICUBIC mode');
24+
test(imagescale($src, $size / 2, $size / 2, IMG_BICUBIC), 'Scale 50%, IMG_BICUBIC mode');
25+
?>
26+
--EXPECT--
27+
No scaling - Test Result: pass
28+
Scale 200%, default mode - Test Result: pass
29+
Scale 50%, default mode - Test Result: pass
30+
Scale 200%, IMG_BICUBIC mode - Test Result: pass
31+
Scale 50%, IMG_BICUBIC mode - Test Result: pass

0 commit comments

Comments
 (0)