com php-src: Don't enforce palette conversion when writing GD images: UPGRADING ext/gd/gd.c ext/gd/tests/imagegd_truecolor.phpt
ext/gd/tests/imagegd_truecolor.png

From: Date: Sat, 24 Sep 2016 12:46:37 +0000
Subject: com php-src: Don't enforce palette conversion when writing GD images: UPGRADING ext/gd/gd.c ext/gd/tests/imagegd_truecolor.phpt
ext/gd/tests/imagegd_truecolor.png
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-94685@lists.php.net to get a copy of this message
Commit: d95b8eaf31eb0613754b7aa38388cf038ed994fc Author: Christoph M. Becker <cmbecker69@gmx.de> Sat, 24 Sep 2016 14:44:57 +0200 Parents: 96305b456b88361e1fe2be48be11add420f93769 Branches: master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=d95b8eaf31eb0613754b7aa38388cf038ed994fc Log: Don't enforce palette conversion when writing GD images The GD image format is able to handle truecolor images as of libgd 2.0.12 (<https://github.com/libgd/libgd/blob/gd-2.2..3/src/gd_gd.c#L31-L33>). Therefore we don't need the potentially lossy and time consuming palette conversion. This way, imagegd() can also be used to export raw truecolor image data. Changed paths: M UPGRADING M ext/gd/gd.c A ext/gd/tests/imagegd_truecolor.phpt A ext/gd/tests/imagegd_truecolor.png Diff: diff --git a/UPGRADING b/UPGRADING index feef5d6..2c66c42 100644 --- a/UPGRADING +++ b/UPGRADING @@ -95,6 +95,8 @@ PHP 7.2 UPGRADE NOTES - GD: . Removed --enable-gd-native-ttf configuration option which was unused as of PHP 5.5.0 anyway. + . imagegd() stores truecolor images as real truecolor images. Formerly, they + have been converted to palette. - Mbstring . mb_check_encoding() accepts array parameter. Both key and value diff --git a/ext/gd/gd.c b/ext/gd/gd.c index 29e5175..739c069 100644 --- a/ext/gd/gd.c +++ b/ext/gd/gd.c @@ -2565,9 +2565,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char (*func_p)(im, i, fp); break; case PHP_GDIMG_TYPE_GD: - if (im->trueColor){ - gdImageTrueColorToPalette(im,1,256); - } (*func_p)(im, fp); break; case PHP_GDIMG_TYPE_GD2: @@ -2619,9 +2616,6 @@ static void _php_image_output(INTERNAL_FUNCTION_PARAMETERS, int image_type, char (*func_p)(im, q, tmp); break; case PHP_GDIMG_TYPE_GD: - if (im->trueColor) { - gdImageTrueColorToPalette(im,1,256); - } (*func_p)(im, tmp); break; case PHP_GDIMG_TYPE_GD2: diff --git a/ext/gd/tests/imagegd_truecolor.phpt b/ext/gd/tests/imagegd_truecolor.phpt new file mode 100644 index 0000000..1eedae4 --- /dev/null +++ b/ext/gd/tests/imagegd_truecolor.phpt @@ -0,0 +1,34 @@ +--TEST-- +imagegd() writes truecolor images without palette conversion +--SKIPIF-- +<?php +if (!extension_loaded('gd')) die('skip gd extension not available'); +?> +--FILE-- +<?php +require_once __DIR__ . DIRECTORY_SEPARATOR . 'func.inc'; + +$im = imagecreatetruecolor(10, 10); +$white = imagecolorallocate($im, 255, 255, 255); +imagefilledrectangle($im, 0,0, 9,9, $white); +$blue = imagecolorallocate($im, 0, 0, 255); +imagefilledrectangle($im, 3,3, 6,6, $blue); + +ob_start(); +imagegd($im); +$buffer = ob_get_clean(); + +$header = unpack('nsignature/nwidth/nheight/Ctruecolor', $buffer); +printf("signature: %d\n", $header['signature']); +printf("truecolor: %d\n", $header['truecolor']); +printf("size: %d\n", strlen($buffer)); + +test_image_equals_file(__DIR__ . DIRECTORY_SEPARATOR . 'imagegd_truecolor.png', $im); +?> +===DONE=== +--EXPECT-- +signature: 65534 +truecolor: 1 +size: 411 +The images are equal. +===DONE=== diff --git a/ext/gd/tests/imagegd_truecolor.png b/ext/gd/tests/imagegd_truecolor.png new file mode 100644 index 0000000..8c77c9f Binary files /dev/null and b/ext/gd/tests/imagegd_truecolor.png differ

« previous php.cvs (#94685) next »