|
|
 |
June 23rd, 2005, 01:32 PM
|
#1
|
|
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
creating images in php
i want to create a simple image with just text on it.... this is the code i am using. vedana.ttf is in the same directory as the php file.
Code:
<?php
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreate(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'verdana.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>
the error i get is... "cannot be displayed, because it contains errors."
why?!
any help wud b appreciated.
|
|
|
June 23rd, 2005, 04:41 PM
|
#2
|
|
New Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 29
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Hi benbacardi,
I tried your code and got this error
Code:
b>Warning[/b]: imagettftext(): Could not find/open font
what i found is if the path of the font has a space in it imagettftext() doesn't like it. Try moving the font so that the path to it doesn't havea space in it
|
|
|
June 23rd, 2005, 05:30 PM
|
#3
|
|
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
it doesnt have a space in it...
and the reason you probably got that error is probably because you didn't put "verdana.ttf" in the same directory as where u were running the script...
|
|
|
June 24th, 2005, 04:14 AM
|
#4
|
|
New Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 29
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
Yes i did put it in the same dir. What is the exact error you are getting?
|
|
|
June 24th, 2005, 04:29 AM
|
#5
|
|
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
"The image www.bpcu.co.uk/image.php cannot be displayed because it contains errors"
|
|
|
June 24th, 2005, 04:40 AM
|
#6
|
|
New Member
Join Date: Jun 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
waw
hello benbacardi
iam realy search about this script
and want to do it but always have errors 
|
|
|
June 24th, 2005, 04:46 AM
|
#7
|
|
New Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 29
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
benbacardi:
Code:
Warning: imagettftext(): Could not find/open font in /home/httpd/vhosts/bpcu.co.uk/httpdocs/image.php on line 19
Warning: imagettftext(): Could not find/open font in /home/httpd/vhosts/bpcu.co.uk/httpdocs/image.php on line 22
‰PNG
IHDRÂ? C PLTEÿÿÿ€€€<^»,IDATxÅ“Ã*Ã?
 ÷Om7 €o
ÖtÔëˆIEND®B`‚
This is what i see when i view that page it does look like it's the imagettftext() function try hardcoding the path as well as the font name when you decalre it
|
|
|
July 19th, 2005, 11:59 PM
|
#8
|
|
New Member
Join Date: Jul 2005
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0
|
okay, im not ENTIRELY sure what the problem is, but a few things to check
(I used that exact code I was learning it, its off a tutorial site)
1. Check the case of the filename. It may be .TTF
2. change the path from "verdana.ttf" to "./verdana.ttf"
This seems kind of arbitrary, but it may be that its searching for verdana.ttf in the default font directory for whatever OS you're running. Going ./ specifies to use the directory your in. Reply here and tell me if it worked. My code worked when I did that, but I never bothered to try it without the ./
Hope it works.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|