|
Author |
Message |
php4ever
Junior WebHelper
Joined: 10 Oct 2002
Posts: 49
|
Posted:
Wed Jul 03, 2002 3:28 am (21 years, 9 months ago) |
|
While waiting for db server 0002 to be fixed, I thought I'd try to learn how to use PHP to create true type font images and wrote this code:
<?php
header('Content-Type: image/jpeg');
$im = ImageCreate(350,70);
$red = ImageColorAllocate($im, 0xFF, 0x00, 0x00);
$black = ImageColorAllocate($im, 0x00,0x00,0x00);
imagettftext($im, 20, 0,10,40, $black,'times.ttf','The TIMES TTF font');
ImageJPEG($im);
ImageJPEG($im,"myttf.jpg");
imagedestroy($im);
?>
The code doesn't work and I'm not sure why but I think it has s.thing to do with the imagettftext() and not having the correct path to times.ttf. So, if anyone has any ideas about how to make this work, I'd be very pleased to know.
Incidentally, I'm at f2s and they are using GD 1.62.
-- php4ever |
|
|
|
|
php4ever
Junior WebHelper
Joined: 10 Oct 2002
Posts: 49
|
Posted:
Wed Jul 03, 2002 5:21 pm (21 years, 9 months ago) |
|
Just figured out what was wrong with above code and thought I'd share since a) I posed the question and b) apparently I'm not the only one who's experienced difficulties getting TTF fonts to work w/PHP.
So, what was wrong with the code above is that it needed a full path to the font. Even when I re-uploaded the font times.ttf and put it in the same directory as the php script, it refused to work. Also, when I tried to hard-code the complete url to the font it failed. However, when I used the $DOCUMENT_ROOT variable in the path to the font, then it worked.
Here's my revised code, which includes some renamed vars and a color change in addition to using a valid path to the font:
<?php
header('Content-Type: image/jpeg');
$im = ImageCreate(350,70);
$bcolor = ImageColorAllocate($im, 0xFF, 0x00, 0x00);
$fcolor = ImageColorAllocate($im, 0xFF,0xFF,0xFF);
imagettftext($im, 20, 0,10,40, $fcolor,"$DOCUMENT_ROOT/fonts/times.ttf",'The TIMES TTF font');
ImageJPEG($im);
ImageJPEG($im,'myttf.jpg');
imagedestroy($im);
?>
and the url is:
http://www.preservestaffnow.org/expfont.php
Here's 2 more ptrs: when you upload a true type font file it should be uploaded as a binary.
And, make sure to use imagedestroy() at end of your script to free up memory on the server. |
|
|
|
|
php4ever
Junior WebHelper
Joined: 10 Oct 2002
Posts: 49
|
Posted:
Tue Jul 09, 2002 1:16 am (21 years, 9 months ago) |
|
When I run the above script at f2s, it does output the image to the browser but it won't output the image to a file and I'm not sure why. Is it b/c f2s uses GD1.6.2 instead of GD1.8 or is this related to permissions or is this related to safe-mode. If anyone knows why, I'd like to be enlightened. Thanks. |
|
|
|
|
jayant
Team Member
Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India
|
Posted:
Tue Jul 09, 2002 8:07 am (21 years, 9 months ago) |
|
|
|
|
php4ever
Junior WebHelper
Joined: 10 Oct 2002
Posts: 49
|
Posted:
Tue Jul 09, 2002 6:38 pm (21 years, 9 months ago) |
|
Thanks Jayant for your reply.
Okay, I changed the permissions on both the script and the directory so that a new jpg or png should be dynamically created and still I get nothing. Since apparently it's not a permissions thing, perhaps this inability arises due to safe-mode or the GD version @ f2s (1.6.2). In any event, I am unable to dynamically generate a png or a jpg altho' I can output those images via the browser.
So, any more thoughts? |
|
|
|
|
Daniel
Team Member
Joined: 06 Jan 2002
Posts: 2564
|
Posted:
Tue Jul 09, 2002 6:50 pm (21 years, 9 months ago) |
|
Try running the script out of safe mode (I think you can do that at F2S by changing the extension to .cgi and adding a line with the path to PHP at the top). |
________________________________
|
|
|
|
php4ever
Junior WebHelper
Joined: 10 Oct 2002
Posts: 49
|
Posted:
Tue Jul 09, 2002 10:41 pm (21 years, 9 months ago) |
|
and it worked! Thank you, Daniel; I appreciate the tip.
By changing to out-of-safe-mode, I was able to run one script that ouputted an image to a PNG file and another that outputted a different image to a JPG file.
Regards,
php4ever |
|
|
|
|
|
|
You cannot post new topics in this forum. You cannot reply to topics in this forum. You cannot edit your posts in this forum. You cannot delete your posts in this forum. You cannot vote in polls in this forum.
|
Page generation time: 0.121291 seconds :: 18 queries executed :: All Times are GMT
Powered by phpBB 2.0
© 2001, 2002 phpBB Group :: Based on an FI Theme
|