PDA

View Full Version : PHP GD Image help



Recursion
13-11-2008, 08:12 PM
Hello,

I want to create an image in Photoshop and then have a PHP script output data to it, kinda like the Last.FM signatures.

So I have some code, and if I put "echo $text;" into a file it will echo the output (a countdown). How would I make it so that this is put onto a specific place on an image?

Like Tom743's (thanks for the code by the way ;) LOL)
Thanks

Source
13-11-2008, 08:16 PM
Its alot more than just echoing some text onto an image, you have to setup the image first then assign colours etc.... ( gd of course).

I will edit with a very basic script to make a signature using a peice of text from a $_GET request.

So hold up :P

Recursion
13-11-2008, 08:18 PM
I knew it was more complex, im just clueless with GD and PHP in general, I can edit scripts but not create them

Decode
13-11-2008, 08:20 PM
Hello,

I want to create an image in Photoshop and then have a PHP script output data to it, kinda like the Last.FM signatures.

So I have some code, and if I put "echo $text;" into a file it will echo the output (a countdown). How would I make it so that this is put onto a specific place on an image?

Like Tom743's (thanks for the code by the way ;) LOL)
Thanks
If you are trying to input it into a GD image you wont use echo text.



header("Content-type: image/gif");
$image = imagecreatefromgif( "yourbackgroundimage.gif" );
$colour = imagecolorallocate($image, 0, 0, 0); //RGB colour, used for the text color
imagestring( $image, 5, 20, 20, $text, $colour ); //the image background, font size, width, height, text to echo, colour
imagegif( $image );
imagedestroy( $image );

Recursion
13-11-2008, 08:21 PM
Aha thanks :)

+REP :D

EDIT: Gotta spread :P

Source
13-11-2008, 08:22 PM
Note how bad that script is. It limits you in terms of fonts... you will always be stuck with that shocking system font.

Either way it will do what you want, just look into more tuts online which will cover more aspects.

Recursion
13-11-2008, 08:23 PM
Ill steal the font code from the Last.FM code. :P

Decode
13-11-2008, 08:25 PM
Note how bad that script is. It limits you in terms of fonts... you will always be stuck with that shocking system font.
I have had to do it like that for my script because awardspace doesn't allow fonts been uploaded :(

Source
13-11-2008, 08:28 PM
Fair enough, but maybe then get a better host? (not free)

Recursion
13-11-2008, 08:35 PM
Thanks guys :P

Just waiting for Photoshop to finish reinstalling (yawn)

I would +REP but I have to spread for both of you :(

Recursion
13-11-2008, 09:58 PM
Sorry for double post.

I have


header("Content-type: image/gif");
$image = imagecreatefromgif( "christmas.gif" );
$font = 'comic.ttf'; // added the font to use (its in same directory)
$colour = imagecolorallocate($image, 0, 119, 180); //RGB colour, used for the text color
imagestring( $image, 50, 80, 20, $text, $colour ); //the image background, font size, width, height, text to echo, colour
imagegif( $image );
imagedestroy( $image );


But it doesn't seem to be displaying the text in the right font (comic.ttf) on the image...

Dentafrice
13-11-2008, 10:05 PM
Yeah, because imagestring doesn't have a font option :P You're really not plugging $font in anywhere..

Use imagettftext() instead of imagestring() ;)

Recursion
13-11-2008, 10:10 PM
[13-Nov-2008 22:07:02] PHP Warning: Wrong parameter count for imagettftext() in /home/prach/public_html/xmas/index.php on line 77

Line 77:


imagettftext( $image, 50, 80, 20, $text, $colour ); //the image background, font size, width, height, text to echo, colour

Joe!
13-11-2008, 10:11 PM
You might want to look at this, http://uk2.php.net/manual/en/function.imagettftext.php , you should then be able to determine what parameters need to be set :)

Dentafrice
13-11-2008, 10:12 PM
See, look at the PHP.net documentation.. it tells you what you need to know: http://us3.php.net/imagettftext

imagettftext ( resource $image , float $size , float $angle , int $x , int $y , int $color , string $fontfile , string $text )

Recursion
14-11-2008, 07:30 AM
Thanks guys, got it working using the PHP pages ;) (My signature woop woop LOL)

+REP'd everyone I can.

Want to hide these adverts? Register an account for free!