#40158 [Opn->Fbk]: Artifact left on transparent pngs using image filters
| From: | pajoye@php.net | Date: | Thu, 18 Jan 2007 19:54:09 +0000 |
| Subject: | #40158 [Opn->Fbk]: Artifact left on transparent pngs using image filters | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-107740@lists.php.net to get a copy of this message | ||
ID: 40158
Updated by: pajoye@php.net
Reported By: henus at mail dot ru
-Status: Open
+Status: Feedback
Bug Type: GD related
Operating System: Windows XP
PHP Version: 5.2.0
Assigned To: pajoye
New Comment:
"pixel from edge with coord (95,11) have wrong color.
red-98 green-98 blue-164 (why is red>0 and green>0 ????????? 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".
Previous Comments:
------------------------------------------------------------------------
[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 red>0 and green>0 ????????? 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
incorrect image - http://fort-ross.ru/henus/gd/result_incorrect3.png
correct image - http://fort-ross.ru/henus/gd/result_correct3.png
------------------------------------------------------------------------
[2007-01-18 18:51:59] pajoye@php.net
(rgba(255,0,0,xxx)) should have been (rgba(0,0,255,xxx)) but you
noticed it :)
------------------------------------------------------------------------
[2007-01-18 18:51:04] pajoye@php.net
An absolute black image is not what you should expect.
imagefilter($mask, IMG_FILTER_COLORIZE, -255, -255, 0); will replace
the white color with blue (you remove all components but the blue):
http://blog.thepimp.net/misc/bug40158_filtered_mask.png
imagecopy($imagemain, $mask, 0, 0, 0, 0, $imagewidth, $imageheight);
will copy it over the $imagemain, the border of the quadrant will be
blended over black:
http://blog.thepimp.net/misc/bug40158_result.png
Each pixel in your circle are rgb(255,255,255) with some alpha value in
the edges (and only in the edges). You are substracting 255 to the R and
G component, the result is blue.
Now, take a look at this image:
http://blog.thepimp.net/misc/bug40158_correct_filtered_mask.png
It is what you are expecting (if I understand correctly your problem).
The edges of the circle have a blue color with various alpha values
(rgba(255,0,0,xxx)). You can reproduce it by disabling the alpha
blending mode in the mask image (imagealphablending($mask, false); ).
The alpha component will be kept and stored in the image instead of
being used as a blending value.
Let me know if that solves your problem.
By the way, COLORIZE uses gdImageColor. The lines you are referring to
are in the contrast function.
------------------------------------------------------------------------
[2007-01-18 18:32:16] henus at mail dot ru
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.
------------------------------------------------------------------------
[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.
------------------------------------------------------------------------
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=40158&edit=1