#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 Updated by: [EMAIL PROTECTED] Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: Can you *PLEASE* confirm that it works when you disable alpha blending? Answer should be Yes or No, I got the details already. I really do not have the time to explain/ask again and again the same thing. About imagefill, yes, that's a bug. Please open a new one if you like. I will fix it as soon as possible. Previous Comments: [2007-01-19 11:53:03] henus at mail dot ru Yes, the is global problem with alphablending in libgd\gd.c but about imagealphablending($mask, false); // Important!: i absolutely should not care about ebabling\disabling imagealphablending before imagefilter, because of function shoud colorize image by new values of red,gree,blue (!!!there is no alpha in parameters) if IMG_FILTER_COLORIZE will have in parameters alpha, if alphablending enable, value of alpha should allow for calculation of new color values (in gdImageColor it will before new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);) and gdImageSetPixel shoul with disabled alphablending. otherwise function work like merging of two images with alphablending. where: first image - source image from function parameters. second image - correct colorized copy of source image. it is not logically. it is incorrect. another bug in imagefill: this function not only fill image, it is also disable alphablending. php example: ? /* first colorizing */ $im1=imagecreatetruecolor(1,1); imagealphablending($im1, TRUE); $c01=imagecolorallocatealpha($im1,255,0,0,63); imagefill($im1,0,0,$c01); $c01=imagecolorsforindex($im1,imagecolorat($im1,0,0)); imagefilter($im1, IMG_FILTER_COLORIZE, -255, 255, 0); $c1=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* second colorizing */ $im2=imagecreatetruecolor(1,1); imagealphablending($im2, TRUE); $c02=imagecolorallocatealpha($im2,255,0,0,63); imagefill($im2,0,0,$c02); $c02=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* att!!! after imagefill another enabling alphablending */ imagealphablending($im2, TRUE); imagefilter($im2, IMG_FILTER_COLORIZE, -255, 255, 0); $c2=imagecolorsforindex($im2,imagecolorat($im2,0,0)); printbrbefore 1 - ; print_r($c01); printbrafter 1 - ; print_r($c1); printbrbrbefore 2 - ; print_r($c02); printbrafter 2 - ; print_r($c2); ? results: before 1- Array ( [red] = 255 [green] = 0 [blue] = 0 [alpha] = 63 ) after 1 - Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) before 2- Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) after 2 - Array ( [red] = 126 [green] = 128 [blue] = 0 [alpha] = 31 ) where: after 1 - correct result of IMG_FILTER_COLORIZE, because of imagefill disable alphablending after 2 - incorrect result of IMG_FILTER_COLORIZE, because of after imagefill i manually enable alphablending disabling alphablending in code it is good solutions for gdImageColor, but after it is necessary to restore old value of alphaBlendingFlag. [2007-01-18 19:54:09] [EMAIL PROTECTED] pixel from edge with coord (95,11) have wrong color. red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should be red-0 green-0 blue-102) It is blended over the destination pixel. You have to disable alpha blending *before* the imagefilter call. This image: http://blog.thepimp.net/misc/bug40158_black_filtered_mask.png shows exactly what you are trying to do (blue, black or purple, it really does not matter), the script being: $mask=imagecreatefrompng(40158.png); imagealphablending($mask, false); // Important! imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); // save alpha, so we see its value imagesavealpha($mask, true); imagepng($mask,mask1.png); Using your last example, the resulting image is like your result_correct3.png. [2007-01-18 19:37:49] henus at mail dot ru it`s not solve my problem :( first - about blue color - look at my submission from [18 Jan 11:03am UTC] if use imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); the result is http://www.fort-ross.ru/henus/gd/result_incorrect.png with legibly visible artefacts. second - image http://blog.thepimp.net/misc/bug40158_result.png also has artefacts at the adges... pixel from edge with coord (95,11) have wrong color red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should be red-0 green-0 blue-102) third - look at my submission from [18 Jan 5:56pm UTC] why is 255-255=126 one more demo - using imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, 0); mask - http://fort-ross.ru/henus/gd/mask3.png
#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 User updated by: henus at mail dot ru Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: Yes Previous Comments: [2007-01-19 12:02:41] [EMAIL PROTECTED] Can you *PLEASE* confirm that it works when you disable alpha blending? Answer should be Yes or No, I got the details already. I really do not have the time to explain/ask again and again the same thing. About imagefill, yes, that's a bug. Please open a new one if you like. I will fix it as soon as possible. [2007-01-19 11:53:03] henus at mail dot ru Yes, the is global problem with alphablending in libgd\gd.c but about imagealphablending($mask, false); // Important!: i absolutely should not care about ebabling\disabling imagealphablending before imagefilter, because of function shoud colorize image by new values of red,gree,blue (!!!there is no alpha in parameters) if IMG_FILTER_COLORIZE will have in parameters alpha, if alphablending enable, value of alpha should allow for calculation of new color values (in gdImageColor it will before new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);) and gdImageSetPixel shoul with disabled alphablending. otherwise function work like merging of two images with alphablending. where: first image - source image from function parameters. second image - correct colorized copy of source image. it is not logically. it is incorrect. another bug in imagefill: this function not only fill image, it is also disable alphablending. php example: ? /* first colorizing */ $im1=imagecreatetruecolor(1,1); imagealphablending($im1, TRUE); $c01=imagecolorallocatealpha($im1,255,0,0,63); imagefill($im1,0,0,$c01); $c01=imagecolorsforindex($im1,imagecolorat($im1,0,0)); imagefilter($im1, IMG_FILTER_COLORIZE, -255, 255, 0); $c1=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* second colorizing */ $im2=imagecreatetruecolor(1,1); imagealphablending($im2, TRUE); $c02=imagecolorallocatealpha($im2,255,0,0,63); imagefill($im2,0,0,$c02); $c02=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* att!!! after imagefill another enabling alphablending */ imagealphablending($im2, TRUE); imagefilter($im2, IMG_FILTER_COLORIZE, -255, 255, 0); $c2=imagecolorsforindex($im2,imagecolorat($im2,0,0)); printbrbefore 1 - ; print_r($c01); printbrafter 1 - ; print_r($c1); printbrbrbefore 2 - ; print_r($c02); printbrafter 2 - ; print_r($c2); ? results: before 1- Array ( [red] = 255 [green] = 0 [blue] = 0 [alpha] = 63 ) after 1 - Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) before 2- Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) after 2 - Array ( [red] = 126 [green] = 128 [blue] = 0 [alpha] = 31 ) where: after 1 - correct result of IMG_FILTER_COLORIZE, because of imagefill disable alphablending after 2 - incorrect result of IMG_FILTER_COLORIZE, because of after imagefill i manually enable alphablending disabling alphablending in code it is good solutions for gdImageColor, but after it is necessary to restore old value of alphaBlendingFlag. [2007-01-18 19:54:09] [EMAIL PROTECTED] pixel from edge with coord (95,11) have wrong color. red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should be red-0 green-0 blue-102) It is blended over the destination pixel. You have to disable alpha blending *before* the imagefilter call. This image: http://blog.thepimp.net/misc/bug40158_black_filtered_mask.png shows exactly what you are trying to do (blue, black or purple, it really does not matter), the script being: $mask=imagecreatefrompng(40158.png); imagealphablending($mask, false); // Important! imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); // save alpha, so we see its value imagesavealpha($mask, true); imagepng($mask,mask1.png); Using your last example, the resulting image is like your result_correct3.png. [2007-01-18 19:37:49] henus at mail dot ru it`s not solve my problem :( first - about blue color - look at my submission from [18 Jan 11:03am UTC] if use imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); the result is http://www.fort-ross.ru/henus/gd/result_incorrect.png with legibly visible artefacts. second - image http://blog.thepimp.net/misc/bug40158_result.png also has artefacts at the adges... pixel from edge with coord (95,11) have wrong color red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should be red-0 green-0 blue-102) third - look at my submission from [18 Jan 5:56pm UTC] why is 255-255=126 one more
#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 User updated by: henus at mail dot ru Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: Yes, it work Previous Comments: [2007-01-19 12:04:39] henus at mail dot ru Yes [2007-01-19 12:02:41] [EMAIL PROTECTED] Can you *PLEASE* confirm that it works when you disable alpha blending? Answer should be Yes or No, I got the details already. I really do not have the time to explain/ask again and again the same thing. About imagefill, yes, that's a bug. Please open a new one if you like. I will fix it as soon as possible. [2007-01-19 11:53:03] henus at mail dot ru Yes, the is global problem with alphablending in libgd\gd.c but about imagealphablending($mask, false); // Important!: i absolutely should not care about ebabling\disabling imagealphablending before imagefilter, because of function shoud colorize image by new values of red,gree,blue (!!!there is no alpha in parameters) if IMG_FILTER_COLORIZE will have in parameters alpha, if alphablending enable, value of alpha should allow for calculation of new color values (in gdImageColor it will before new_pxl = gdImageColorAllocateAlpha(src, (int)r, (int)g, (int)b, a);) and gdImageSetPixel shoul with disabled alphablending. otherwise function work like merging of two images with alphablending. where: first image - source image from function parameters. second image - correct colorized copy of source image. it is not logically. it is incorrect. another bug in imagefill: this function not only fill image, it is also disable alphablending. php example: ? /* first colorizing */ $im1=imagecreatetruecolor(1,1); imagealphablending($im1, TRUE); $c01=imagecolorallocatealpha($im1,255,0,0,63); imagefill($im1,0,0,$c01); $c01=imagecolorsforindex($im1,imagecolorat($im1,0,0)); imagefilter($im1, IMG_FILTER_COLORIZE, -255, 255, 0); $c1=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* second colorizing */ $im2=imagecreatetruecolor(1,1); imagealphablending($im2, TRUE); $c02=imagecolorallocatealpha($im2,255,0,0,63); imagefill($im2,0,0,$c02); $c02=imagecolorsforindex($im1,imagecolorat($im1,0,0)); /* att!!! after imagefill another enabling alphablending */ imagealphablending($im2, TRUE); imagefilter($im2, IMG_FILTER_COLORIZE, -255, 255, 0); $c2=imagecolorsforindex($im2,imagecolorat($im2,0,0)); printbrbefore 1 - ; print_r($c01); printbrafter 1 - ; print_r($c1); printbrbrbefore 2 - ; print_r($c02); printbrafter 2 - ; print_r($c2); ? results: before 1- Array ( [red] = 255 [green] = 0 [blue] = 0 [alpha] = 63 ) after 1 - Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) before 2- Array ( [red] = 0 [green] = 255 [blue] = 0 [alpha] = 63 ) after 2 - Array ( [red] = 126 [green] = 128 [blue] = 0 [alpha] = 31 ) where: after 1 - correct result of IMG_FILTER_COLORIZE, because of imagefill disable alphablending after 2 - incorrect result of IMG_FILTER_COLORIZE, because of after imagefill i manually enable alphablending disabling alphablending in code it is good solutions for gdImageColor, but after it is necessary to restore old value of alphaBlendingFlag. [2007-01-18 19:54:09] [EMAIL PROTECTED] pixel from edge with coord (95,11) have wrong color. red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should be red-0 green-0 blue-102) It is blended over the destination pixel. You have to disable alpha blending *before* the imagefilter call. This image: http://blog.thepimp.net/misc/bug40158_black_filtered_mask.png shows exactly what you are trying to do (blue, black or purple, it really does not matter), the script being: $mask=imagecreatefrompng(40158.png); imagealphablending($mask, false); // Important! imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); // save alpha, so we see its value imagesavealpha($mask, true); imagepng($mask,mask1.png); Using your last example, the resulting image is like your result_correct3.png. [2007-01-18 19:37:49] henus at mail dot ru it`s not solve my problem :( first - about blue color - look at my submission from [18 Jan 11:03am UTC] if use imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, -255); the result is http://www.fort-ross.ru/henus/gd/result_incorrect.png with legibly visible artefacts. second - image http://blog.thepimp.net/misc/bug40158_result.png also has artefacts at the adges... pixel from edge with coord (95,11) have wrong color red-98 green-98 blue-164 (why is red0 and green0 ? after substracting 255???) (should
#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 Updated by: [EMAIL PROTECTED] Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: Please provide an *image* showing what you expect. Previous Comments: [2007-01-18 17:56:25] henus at mail dot ru 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 ) [2007-01-18 15:22:49] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] ...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); The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/40158 -- Edit this bug report at http://bugs.php.net/?id=40158edit=1
#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 User updated by: henus at mail dot ru Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: correction fo my previous post about php-5.2.0\ext\gd\libgd\gd.c Lines 3682-3688: 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); } if ((y = 0) (y src-sy)) { gdImageSetPixel (src, x, y, new_pxl); in gdImageSetPixel src should be absolutely transparent, with alpha=127 differently it mix colors. Previous Comments: [2007-01-18 18:09:31] [EMAIL PROTECTED] Please provide an *image* showing what you expect. [2007-01-18 17:56:25] henus at mail dot ru 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 ) [2007-01-18 15:22:49] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] ...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... The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/40158 -- Edit this bug report at http://bugs.php.net/?id=40158edit=1
#40158 [Opn]: Artifact left on transparent pngs using image filters
ID: 40158 User updated by: henus at mail dot ru Reported By: henus at mail dot ru Status: Open Bug Type: GD related Operating System: Windows XP PHP Version: 5.2.0 Assigned To: pajoye New Comment: i expect absolutely black image like http://www.fort-ross.ru/henus/gd/result_correct.png instead of http://www.fort-ross.ru/henus/gd/result_incorrect.png i use colorizing by black for clearness. Previous Comments: [2007-01-18 18:11:31] henus at mail dot ru correction fo my previous post about php-5.2.0\ext\gd\libgd\gd.c Lines 3682-3688: 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); } if ((y = 0) (y src-sy)) { gdImageSetPixel (src, x, y, new_pxl); in gdImageSetPixel src should be absolutely transparent, with alpha=127 differently it mix colors. [2007-01-18 18:09:31] [EMAIL PROTECTED] Please provide an *image* showing what you expect. [2007-01-18 17:56:25] henus at mail dot ru 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 ) [2007-01-18 15:22:49] [EMAIL PROTECTED] 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] [EMAIL PROTECTED] ...should be without alpha... Could you plz elaborate? A unified diff would explain it much better, btw. The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/40158 -- Edit this bug report at http://bugs.php.net/?id=40158edit=1