ImageCreate Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
spib
Forum Newbie
Posts: 9
Joined: Wed Jul 09, 2003 2:09 am

ImageCreate Problem

Post by spib »

Hey Guys,

I have a visual verify code script for my web site which works on my local WinXP system but not on my remote linux system. The script basically creates an image containging ranfom sized characters based on the text which is passed in as an argument.

The problem I have is that the image won't render - I just get a 'red x' image missing.

The syntax to call the script is

Code: Select all

require('visual_verify_code.php');
vvcode_render_code('test');
The script itself is

Code: Select all

function vvcode_render_code($code) {
        if (!empty($code)) {
            $imwidth=100;
            $imheight=25;
            Header("Content-type: image/Jpeg");
            $im = @ImageCreate ($imwidth, $imheight) or die ("ERROR! Cannot create new GD image - see: verify_code_img_gen.php");

            $background_color = ImageColorAllocate ($im, 255, 255, 255);
            $text_color = ImageColorAllocate ($im, 0, 0, 0);
            $border_color = ImageColorAllocate ($im, 154, 154, 154);

            //strip any spaces that may have crept in
            //end-user wouldn't know to type the space! :)
            $code = str_replace(" ", "", $code);
            $x=0;

            $stringlength = strlen($code);
            for ($i = 0; $i< $stringlength; $i++) &#123;
                 $x = $x + (rand (8, 15));
                 $y = rand (2, 10);
                 $font = rand (2,5);
                 $single_char = substr($code, $i, 1);
                 imagechar($im, $font, $x, $y, $single_char, $text_color);
                &#125;

            imagerectangle ($im, 2, 2, $imwidth-2, $imheight-2, $border_color);

            ImageJpeg($im);
            ImageDestroy;
        &#125;
  &#125;
Can anyone suggest which the problem is? The following is my system and GD output from phpinfo()

Code: Select all

System  Linux myhostname 2.4.24 #3 Tue Jan 6 03:49:53 GMT 2004 i686  
Build Date  Apr 17 2004 11:57:22  
Configure Command  './configure' '--with-apxs=/usr/local/apache/bin/apxs' '--with-xml' '--enable-bcmath' '--enable-calendar' '--with-curl' '--enable-ftp' '--with-gd' '--with-jpeg-dir=/usr/local' '--with-png-dir=/usr' '--with-xpm-dir=/usr/X11R6' '--with-gettext' '--with-imap' '--with-imap-ssl' '--with-kerberos' '--with-mcrypt' '--enable-magic-quotes' '--with-mysql' '--with-openssl' '--enable-discard-path' '--with-pear' '--enable-xslt' '--with-xslt-sablot' '--enable-sockets' '--enable-track-vars' '--with-ttf' '--with-freetype-dir=/usr' '--enable-gd-native-ttf' '--enable-versioning' '--with-xmlrpc' '--with-zlib'  
Server API  Apache  
Virtual Directory Support  disabled  
Configuration File (php.ini) Path  /usr/local/Zend/etc/php.ini  
PHP API  20020918  
PHP Extension  20020429  
Zend Extension  20021010  
Debug Build  no  
Thread Safety  disabled  
Registered PHP Streams  php, http, ftp, https, ftps, compress.zlib

Code: Select all

GD Support  enabled  
GD Version  bundled (2.0.15 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
GIF Read Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XBM Support  enabled
Post Reply