Gd php?

software development

#1

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


#2

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


#3

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!! :@

You act on my advice at your own risk!


#4

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

[code]<?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);
?>
[/code]


#5

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

–rlparker