adding text on an already made image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

adding text on an already made image

Post by JohnDigweed »

Hi,

I have a business card site, and I want to have users to be able to add text on the business card image to see what it looks like.

First, I need to know how to add text on an already made image. Its a white business card :

<?
header ("Content-type: image/jpg");
$image = imagecreatefromjpeg ("blank.jpg");
$black = imagecolorresolve ($image, 0, 0, 0);
imagettftext ($image, 20, 0, 10, 20, $black, "Test Text");
imagejpeg($image,'',90);
imagedestroy($image);
?>

However, I see only the picture. No text! I dont know whats wrong!

I would be thankful for any help. :)
Last edited by JohnDigweed on Sun Apr 04, 2004 9:49 am, edited 1 time in total.
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

Code: Select all

header("Content-type: image/jpeg");
 $fontname = "arial";
 $fontsize = 12;
 $im = imagecreate(400,30);
 $white = imagecolorallocate($im, 255,255,255);
 $black = imagecolorallocate($im, 0,0,0);
 $text = "Hello world";
 imagettfbbox($im, $fontsize, 0, 0, 0, $white, $fontname, $text);
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Hi,

ok Thanks for that. How would I add that ontop of an already made image?

Thanks.
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Can anyone help? my script that I posted at the top will not work. No text will show.

Thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

<?php
header ("Content-type: image/jpg");
$image = imagecreatefromjpeg ("blank.jpg");
$black = imagecolorresolve ($image, 0, 0, 0);
imagettftext ($image, 20, 0, 10, 20, $black, 'arial.ttf', 'Test Text');
imagejpeg($image,'',90);
imagedestroy($image);
?>
.. works for me :o
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Could it possibly be the JPEG im using?

Also, does the TTF have to be uploaded to my web site?

is IMage color resolve same thing as imageallocate?

Thanks :)
Post Reply