GD PHP?

GD PHP?

Posted by: larrygfremont
Posted on: 2008-04-12 21:24:00

I'm a newbie at PHP. I'm trying to get the GD imaging library to work for the CAPTCHA routine of an open source Guest Book. The images turn out empty. Can someone supply a PHP code snippet that would demonstrate that the GD library on Dreamhost actually works?

Here is a link to the Guest Book webpage:
http://www.myphpscripts.net/?sid=6


Re: GD PHP?

Posted by: rlparker
Posted on: 2008-04-13 02:16:00

In reply to:

Can someone supply a PHP code snippet that would demonstrate that the GD library on Dreamhost actually works?


Sure!

<?PHP
if (imagetypes() & IMG_GIF) echo "GIF Support is enabled<br />";
if (imagetypes() & IMG_JPG) echo "JPEG Support is enabled<br />";
if (imagetypes() & IMG_PNG) echo "PNG Support is enabled<br />";
if (imagetypes() & IMG_WBMP) echo "WBMP Support is enabled<br />";
?>

Lot's more qucik little snippets at this great resource:

http://nyphp.org/content/presentations/GDintro/

--rlparker

Re: GD PHP?

Posted by: norm1037
Posted on: 2008-04-13 09:42:00

They do work because I use them to create this image daily.

Check through the PHP code to see if any fonts are used and if so if the code is pointing to those fonts.

For example if you were using Vera.ttf you would use:-

/usr/share/fonts/truetype/ttf-bitstream-vera/Vera.ttf

If it is a font that you uploaded to work with the captcha php the same would apply. Check the path to the font or images.



--
Norm


Opinions are my own views, not DreamHosts'.
I am NOT a DreamHost employee OK!! mad

You act on my advice at your own risk!

Re: GD PHP?

Posted by: larrygfremont
Posted on: 2008-04-15 12:22:00

To answer my own question, try browsing to a page containing (only) this code, in a file with extension .php (substituting your own font):

<?php
// Set the content-type
header("Content-type: image/png");

$height = 43;
$width = 160;
$font = 'guestbook/fonts/captcha.ttf';

$image_p = imagecreate($width, $height);

$black = imagecolorallocate($image_p, 0, 0, 0);
$grey = imagecolorallocate($image_p, 128, 128, 128);

imagefilledrectangle($image_p, 0, 0, $width - 1, $height - 1, $grey);

imagettftext($image_p, 22, 0, 10, 30, $black, $font, "Hello, World!");

imagepng($image_p);

imagedestroy($image_p);
?>

Re: GD PHP?

Posted by: rlparker
Posted on: 2008-04-15 15:20:00

It works for me -> http://maddogz.com/dev/gd/test.php wink

--rlparker

Tags: code snippetgd librarydreamhostphp codeguest booknewbiesidopen sourceimages