#40158 [Fbk->Opn]: Artifact left on transparent pngs using image filters

From: Date: Thu, 18 Jan 2007 17:56:27 +0000
Subject: #40158 [Fbk->Opn]: Artifact left on transparent pngs using image filters
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-107732@lists.php.net to get a copy of this message
ID: 40158 User updated by: henus at mail dot ru Reported By: henus at mail dot ru -Status: Feedback +Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: i create black image and overlay it by colorized white-truecolor-png24-image ( http://fort-ross.ru/henus/gd/mask.png ) the result of colorize like: imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); is image: http://www.fort-ross.ru/henus/gd/result_incorrect.png which contain artefacts... also, the result of such script ( http://fort-ross.ru/henus/gd/demo2.phps ) is: is truecolor - 1 before - Array ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 63 ) wrong result, using filter - Array ( [red] => 126 [green] => 126 [blue] => 126 [alpha] => 31 ) wrong result, using imagecolorallocatealpha and imagesetpixel - Array ( [red] => 126 [green] => 126 [blue] => 126 [alpha] => 31 ) correct result, using imagefill, imagecolorallocatealpha and imagesetpixel - Array ( [red] => 0 [green] => 0 [blue] => 0 [alpha] => 63 ) I.e. colorizing pixel ( [red] => 255 [green] => 255 [blue] => 255 [alpha] => 63 ) to black should be with ( [red] => 0 [green] => 0 [blue] => 0 [alpha] => 63 ), not ( [red] => 126 [green] => 126 [blue] => 126 [alpha] => 31 ) Previous Comments: ------------------------------------------------------------------------ [2007-01-18 15:22:49] pajoye@php.net Can you provide an image to show what you expect? I did not check your script but having an image will help to really understand what you are trying to achieve. By the way, filters work only with truecolor images, allocate will never fail. ------------------------------------------------------------------------ [2007-01-18 14:26:28] tony2001@php.net >...should be without alpha... Could you plz elaborate? A unified diff would explain it much better, btw. ------------------------------------------------------------------------ [2007-01-18 14:23:38] henus at mail dot ru php-5.2.0\ext\gd\libgd\gd.c Lines 3682-3685: new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a); if (new_pxl == -1) { new_pxl = gdImageColorClosestAlpha(src, (int)r, (int)g, (int)b, a); } ....should be without alpha... ------------------------------------------------------------------------ [2007-01-18 11:03:15] henus at mail dot ru My mistake... correct 12 line in Reproduce code: imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); ------------------------------------------------------------------------ [2007-01-18 10:40:42] henus at mail dot ru Description: ------------ After using imagefilter (IMG_FILTER_COLORIZE) on transparent png image the result color of translucent pixels is wrong. I.e. the edge of non-transparent part of image, which contain translucent antialiasing area - wrong colored. Reproduce code: --------------- <? $mask=imagecreatefrompng("mask.png"); // http://fort-ross.ru/henus/gd/mask.png (mask for colorize, contain translucent) $imagewidth=imagesx($mask); $imageheight=imagesy($mask); $imagemain=imagecreatetruecolor($imagewidth,$imageheight); imagealphablending($mask, TRUE); imagealphablending($imagemain, TRUE); $color=imagecolorallocate($imagemain, 0, 0, 0); imagefill($imagemain, 0, 0, $color); imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, 0); imagecopy($imagemain, $mask, 0, 0, 0, 0, $imagewidth, $imageheight); imagepng($imagemain,"result_incorrect.png"); // http://www.fort-ross.ru/henus/gd/result_incorrect.png imagedestroy($mask); imagedestroy($imagemain); ?> Expected result: ---------------- The result image - absolutely black square Actual result: -------------- The result image - black square with gray line (on the edge of mask image) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=40158&edit=1

« previous php.bugs (#107732) next »