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);

Link to comment
Share on other sites

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);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.