View Single Post
Old 29-05-2004, 19:50   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: Image manipulation

I've already written something similiar. I was writing it so I can have a random generated sig on this board. It basically works, but I still want to tweak the text position/alignment but anyway, here is the important code:

Code:
<?php

//define what pic you want to alter and text
$thepic = 'img.jpg';
$thestring= "text\ntext";  //  \n for new line

//load the image (also you can use imagecreatefromgif)
$im = imagecreatefromjpeg($thepic);


//blue text
$textcolor = imagecolorallocate($im, 0, 0, 255);
 
//write text - the number params are: fontsize, angle to write, x position, y position
imagettftext($im, 12, 0, 0, 0, $textcolor,'arial.ttf',$thestring);

//output image to browser.
  header("Content-type: image/jpg");
  imagejpeg($im);

?>
Note: you can't output GIFs due to Compuserve copyright law. If you want to output transparency, use content-type: image/png, and imagepng. Also, the font has to be stored locally on the server. So just copy arial.ttf from c:\windows\fonts and upload it to your server.

To call it, include this in your HTML file:

Code:
<img src="imagemanipulated.php"></img>
If you want more info go to: http://uk.php.net/manual/en/function.imagettftext.php

HTH
punky is offline   Reply With Quote