|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-05-17 21:43 UTC] lieyang at yahoo dot com
Description: ------------ When resizing a 24 bit png image with imagecopyresampled, the destination image alpha channel contains noise where it should be completely transparent. When the re-sized image is displayed on Motorola phones with only 4 levels of transparency, the image shows many dark dots. If we replace imagecopyresampled with imagecopyresized in the following sample reproduce code, the problem goes away. Reproduce code: --------------- $imageSrc = imagecreatefromstring($imageData); $imageDst = imagecreatetruecolor($width, $height); imagealphablending($imageDst, false); $color = imagecolorallocatealpha($imageDst, 0, 0, 0, 127); imagefill($imageDst, 0, 0, $color); imagesavealpha($imageDst, true); imagecopyresampled($imageDst,$imageSrc, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); Expected result: ---------------- Completely transparent regions should still be completely transparent in destination image. Actual result: -------------- Destination image alpha channel noise (some pixel values that should be fully transparent have different value "2"). You can see the noise all over the transparent regions with any graphics tools (for example, color selection with gimp). PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 00:00:01 2025 UTC |
We need a better reproducible example here, including the source image. When the source image has a perfect alpha channel, I see no noise. Try this: $imageSrc = imagecreatetruecolor(500, 500); imagealphablending($imageSrc, false); imagesavealpha($imageSrc, true); $color = imagecolorallocatealpha($imageSrc, 0, 0, 0, 127); imagefill($imageSrc, 0, 0, $color); $imageDst = imagecreatetruecolor(50, 50); imagealphablending($imageDst, false); imagesavealpha($imageDst, true); imagecopyresampled($imageDst,$imageSrc, 0, 0, 0, 0, 50, 50, 500, 500); header('Content-type: image/png'); imagepng($imageDst);Please try the following with different image sizes and you will see that the alpha channel has noise. (I have two original before and after images but can not find the link to upload them as attachments) $imageSrc = imagecreatetruecolor(90, 90); imagealphablending($imageSrc, false); imagesavealpha($imageSrc, true); $color = imagecolorallocatealpha($imageSrc, 0, 0, 0, 127); imagefill($imageSrc, 0, 0, $color); $imageDst = imagecreatetruecolor(56, 56); imagealphablending($imageDst, false); imagesavealpha($imageDst, true); imagecopyresampled($imageDst,$imageSrc, 0, 0, 0, 0, 56, 56, 90, 90); header('Content-type: image/png'); imagepng($imageDst);