creating images in php

This is a discussion on "creating images in php" within the PHP Forum section. This forum, and the thread "creating images in php are both part of the Program Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Jun 23rd, 2005, 17:32
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
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: Select all
<?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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Jun 23rd, 2005, 20:41
Junior Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 28
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Hi benbacardi,

I tried your code and got this error
Code: Select all
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Jun 23rd, 2005, 21:30
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
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...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Jun 24th, 2005, 08:14
Junior Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 28
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Yes i did put it in the same dir. What is the exact error you are getting?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Jun 24th, 2005, 08:29
benbacardi's Avatar
Highly Reputable Member
Join Date: Feb 2004
Location: United Kingdom
Age: 20
Posts: 611
Thanks: 0
Thanked 0 Times in 0 Posts
"The image www.bpcu.co.uk/image.php cannot be displayed because it contains errors"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Jun 24th, 2005, 08:40
New Member
Join Date: Jun 2005
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
waw

hello benbacardi
iam realy search about this script
and want to do it but always have errors
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Jun 24th, 2005, 08:46
Junior Member
Join Date: Apr 2005
Location: Llanelli, South Wales
Age: 28
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
benbacardi:

Code: Select all

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Jul 20th, 2005, 03:59
Junior Member
Join Date: Jul 2005
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
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.
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

Tags
creating, images, php

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 Web Page Design 4 Apr 18th, 2008 09:11
creating logos, backgrounds and images Aesir Graphics and 3D 8 Mar 10th, 2008 14:39
Creating rollover images in photoshop Kurt Graphics and 3D 8 Sep 9th, 2007 21:11
Creating a sum with ASP Andrew1986 Classic ASP 4 Aug 1st, 2007 10:09
creating new div class + making images links TardPress PHP Forum 1 Jun 19th, 2006 03:04


All times are GMT. The time now is 02:17.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42