Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GD Library add text to image 1

Status
Not open for further replies.

overflo

Technical User
Feb 10, 2003
70
AU
Hi. Has anyone had any success with using the GD library to write text on an image. I have trawled the 'net and tried various methods but none will work. I have tried them all on 4 separate servers - all with GD enabled, FreeType Support enabled, FreeType Linkage with FreeType, GetText Support enabled (if they are relevant). I have been able to create a border around an image but the text on image is still eluding me.
Any suggestions will be greatly appreciated.

Cheers
 
what errors are being reported? i don't remember this being difficult but have not tried for some time.
 
No errors, just the image remains unchanged.
 
this, for example, works fine for me

Code:
<?php

//get tektips logo
$im = imagecreatefromgif('[URL unfurl="true"]http://www.tek-tips.com/images/logo.gif');[/URL]

//get the image size
$w = imagesx($im);
$h = imagesy($im);

//now create the text on a new canvas (i've used identical sized canvases but in practice you probably will not want to do so)
$text = imagecreatetruecolor($w, $h);
//place some text at the top left
imagestring($text, 5, 0, 0, 'Tek-Tips', 0x0000FF);


// merge the two canvas
//set opacity to 50%
imagecopymerge($im, $text, 0, 0, 0, 0, $w, $h, 50);

// output the image
header('Content-Type: image/png');
imagepng($im);
imagedestroy ($text);
imagedestroy($im);
?>
 
Yay it works.

Thankyou....Your blood is worth bottling.

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top