Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old June 23rd, 2005, 01:32 PM   #1
Highly Reputable Member
 
benbacardi's Avatar
 

Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 benbacardi will become famous soon enough
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.
benbacardi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 markj is on a distinguished road
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
markj is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 23rd, 2005, 05:30 PM   #3
Highly Reputable Member
 
benbacardi's Avatar
 

Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 benbacardi will become famous soon enough
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...
benbacardi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 markj is on a distinguished road
Yes i did put it in the same dir. What is the exact error you are getting?
markj is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 24th, 2005, 04:29 AM   #5
Highly Reputable Member
 
benbacardi's Avatar
 

Join Date: Feb 2004
Location: United Kingdom
Age: 22
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 benbacardi will become famous soon enough
"The image www.bpcu.co.uk/image.php cannot be displayed because it contains errors"
benbacardi is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 astm is on a distinguished road
waw

hello benbacardi
iam realy search about this script
and want to do it but always have errors
astm is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 markj is on a distinguished road
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
markj is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old 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 phleet is on a distinguished road
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.
phleet is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
creating , images , php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
multiple rollover images change multiple images joshlindem HTML, XHTML and CSS 4 April 18th, 2008 05:11 AM
creating logos, backgrounds and images Aesir Graphic Specifics 8 March 10th, 2008 11:39 AM
Creating rollover images in photoshop Kurt Graphic Specifics 8 September 9th, 2007 05:11 PM
Creating a sum with ASP Andrew1986 Classic ASP 4 August 1st, 2007 06:09 AM
creating new div class + making images links TardPress PHP 1 June 18th, 2006 11:04 PM


Search Engine Optimization by vBSEO 3.2.0 RC8