Does real transparency work with imagettftext and imagecolortproparparent?

When using imagettftext with an image transparent with imagecolortransparent, the border of the text seems to blend with the original background color (black) instead of transparency, thus creating text text, as shown here:
http://i.stack.imgur.com/xLSkK.png , unlike using imagestring, here:
http://i.imgur.com/5R0gT.png

Now I'm not sure if there is a better way to combine the images so that they are created from the very beginning, or if there is another way of transparency that I do not know about. Here is the relevant PHP code I'm using:

if ($type) { $icon = imagecreatefrompng("images/" . $type . ".png"); } else { die('Invalid type. Valid types are: arcane, elysian, divine, spectral'); } $img = imagecreatetruecolor(128, 25); $black = imagecolorallocate($img, 0, 0, 0); imagecolortransparent($img, $black); imagecopymerge($img,$icon,0,0,0,0,28,25,100); imagettftext( $img, 16, 0, 30, 20, $col, $font, $input_num ); header( "Content-type: image/png" ); imagepng( $img ); 
+4
source share
1 answer

imagecolortransparent will never work very well due to anti-aliasing --- the background color near the outlines is not true black. It is best to use PNG images with transparent areas in the first place, and not with a black background.

+1
source

Source: https://habr.com/ru/post/1380492/


All Articles