Jump to content

Image text underline or italic?


godsent

Recommended Posts

Is it possible to make text on image underlined or italic? And if its possible to make part of text normal and another part (italic)? And the last question is my code for writing text is proper?

 

$text = wrap(12, 0, "arial.ttf", "One day, Two days, Three days and all other days.",300); 
$font = "arial.ttf";
$size = "12";

$width = 300;
$height = 400;

$image = imagecreatetruecolor($width, $height); //blank img

$bgcolor = imagecolorallocate($image, 255, 255, 255); // white
$color = imagecolorallocate($image, 0, 0, 0); //black

$x = 10; //begin write on x
$y = 20; //begin write

imagefilledrectangle($image, 0, 0, $width - 1, $height - 1, $bgcolor);
imagettftext($image, $size, 0, $x, $y, $color, $font, $text);

header('Content-type: image/png');
imagepng($image);
imagedestroy($image);

function wrap($fontSize, $angle, $fontFace, $string, $width){
   
    $ret = "";
   
    $arr = explode(' ', $string);
   
    foreach ( $arr as $word ){
   
        $teststring = $ret.' '.$word;
        $testbox = imagettfbbox($fontSize, $angle, $fontFace, $teststring);
        if ( $testbox[2] > $width ){
            $ret.=($ret==""?"":"\n").$word;
        } else {
            $ret.=($ret==""?"":' ').$word;
        }
    }
   
    return $ret;
}

Link to comment
Share on other sites

With the gd library the only way you will accomplish italic bold text is with a custom function. To make the text bold you could use a font like "Arial Black" or display the text twice with the second text having an x offset of +1. To make it italic you will need to loop through each character and display each character on an angle. Hope that helps.

Link to comment
Share on other sites

If bold underlined is what you want.. then a bold underlined custom font you'll need to make.. (at least that's the easiest way I can think of doing it)

 

I'm not too sure how TTF works with GD Library but I do know that you can create a GDF font from a TTF font, using this program http://www.wedwick.com/wftopf.exe.  You can load up Arial Black... set your desired size, styles, etc.. and save it; upload it to your server and use it.

 

By use it I mean, use this function  imageloadfont

.... and :rtfm: too

 

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.