Jump to content

[SOLVED] text has white edges using imagettftext in transparent png


bobinindia

Recommended Posts

Creating text with imagettftext

When the text comes back it isn't very clean.

Is there something I can do to keep the edges of the text smooth.

I set the imagepng to no compression(0).

 

$mask = imagecreatetruecolor($x,$newy);
$tcolour = imagecolorallocate($mask,254,255,255);

imagefilledrectangle($mask, 0, 0, $x, $newy, $tcolour); // Or draw other background.
imagecolortransparent($mask, $tcolour);

$color = rgb2hex2rgb($colour);
        $one = $color[0];
        $two = $color[1];
        $three = $color[2];
        
$txtcol = imagecolorallocate($mask, $one, $two, $three);
imagettftext($mask,$fontsize, 0, 0, $y, $txtcol, $font, $txt);
//stopcache is a timerelated number.
$imurl = "images/transtext/".$stopcache.".png";


imagepng($mask, $imurl, 0); 
imagedestroy($mask);

Solved it.

By making the transparent color one of the RGB values - 1 or +1.

The eye can't see it.

$color = rgb2hex2rgb($colour);
        $one = $color[0];
        $two = $color[1];
        $three = $color[2];
        if ($three<255){
            $replace = $three +1;
        } else {
            $replace = $three - 1;
        }
$tcolour = imagecolorallocate($mask,$one,$two,$replace);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.