p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 (http://p2p.wrox.com/forumdisplay.php?f=476)
-   -   Ch 7 imagettftext function failing to find fonts (http://p2p.wrox.com/showthread.php?t=73949)

sgtwwilson April 15th, 2009 09:01 PM

Ch 7 imagettftext function failing to find fonts
 
I am new to all of this and I have been struggling to get the imagettftext() function to work as it is written in the chapter 7 code.

The putenv('GDFONTPATH=' . 'C:/Windows/Fonts') does not seem to facilitate the use of fonts in the Windows font folder...

This bit of code below is taken from the book:

PHP Code:

//change this path to match your fonts directory and the desired font
putenv('GDFONTPATH=' 'C:/Windows/Fonts');
$font 'arial';

(
SNIP)

// add the caption if requested
if (isset($_GET['capt'])) {
    
imagettftext($image12020200$font$_GET['capt']);


The only way I have gotten it to work is to set $font = 'arial.ttf' and place the arial.ttf file into my ...apache2.2/htdoc folder.

I would love to know why the putenv call is not working; any help would be appreciated.

Thanks
-K

peirix April 29th, 2009 08:04 AM

Yeah, I'm getting the same error.

Tried copying the font into my htdocs folder, but that didn't work either.

Anyone knows why this is? Tried switching the /'s with \'s, but didn't help.

aformoftruth January 27th, 2010 08:37 AM

Chapter 7 Image Caption & Watermark?
 
Me too i cant even get the above workaround to work...

I can't get the Caption & Watermark to work on page 202 onwards?!

I have downloaded the original code...changed the paths to my htdocs. But this still doesn't work....everything else but this.

Help.

BozHogan February 13th, 2010 01:48 AM

Solution or workaround
 
I replaced the two relevant lines of codes at the top of both check_image.php and image_effect.php with the following:

Code:

putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';

This solved the problem, at least on Windows Vista.

HTH,
Boz

BozHogan February 13th, 2010 02:22 AM

And BTW, don't put any debugging statements in the image_effect.php file, like echo $font, or anything else that causes output. Because this file is called as the src attribute of an image element, it can only generate an image, not text output. When I tried to use echo to see what my variables and arrays were holding, the check_image program tried to put that where it expected an image. The result was no image, and annoyingly, no output or even an error message in the php-error log.

I think using an image generating program as the src attribute is pretty cool. But if anyone knows a way to get error and debugging info out of it, I'd love to here it. There must be a way to use stderr or stdout to do this on Linux, but on Windows? Any ideas?

Regards,
Boz

rickymartini76@yahoo.it March 3rd, 2010 12:02 PM

Quote:

Originally Posted by BozHogan (Post 253531)
I replaced the two relevant lines of codes at the top of both check_image.php and image_effect.php with the following:

Code:

putenv("GDFONTPATH=" . "C:/Windows/Fonts/");
$font = getenv('GDFONTPATH') . 'arial.ttf';

This solved the problem, at least on Windows Vista.

HTH,
Boz

After this replaced lines i have the same problem... The code does'nt work!
Can you Help me?


All times are GMT -4. The time now is 10:07 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.