Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762

    * [PHP] Issues with dynamically generated images

    Hello,

    I use the following function to generate error images:

    PHP Code:
    function generateErrorImage($msg)
    {
        
    // Set Error Message
        
    $error_msg = (isset($msg) ? $msg 'Unknown');

        
    // Set Image Properties
        
    $im_font_size 2;
        
    $im_padding 5;
        
    $im_width = (imagefontwidth($im_font_size) * strlen($error_msg) + ($im_padding 2));
        
    $im_height = (imagefontheight($im_font_size) + ($im_padding 2));

        
    // Generate Image Object
        
    $im imagecreatetruecolor($im_width$im_height);
        
    $bgc imagecolorallocate($im255236236);
        
    $tc imagecolorallocate($im20400);
        
    imagefilledrectangle($im00$im_width$im_height$bgc);
        
    imagestring($im$im_font_size$im_padding$im_padding$error_msg$tc);

        
    // Add Border To Image
        
    $bc imagecolorallocate($im20400);
        
    $x 0;
        
    $y 0;
        
    $w imagesx($im) - 1;
        
    $h imagesy($im) - 1;
        
    imageline($im$x,$y,$x,$y+$h,$bc);
        
    imageline($im$x,$y,$x+$w,$y,$bc);
        
    imageline($im$x+$w,$y,$x+$w,$y+$h,$bc);
        
    imageline($im$x,$y+$h,$x+$w,$y+$h,$bc);

        
    // Output Error Image To Browser
        
    header("Content-Type: image/png");
        
    header('Last-Modified: 'gmdate('D, d M Y H:i:s'strtotime("7 days ago")) .' GMT');
        
    ob_start();
        
    imagepng($im);
        
    $image_data ob_get_contents();
        
    $image_data_length ob_get_length();
        
    ob_end_clean();
        
    header('Content-Length: '$image_data_length);
        echo 
    $image_data;
        
    imagedestroy($im);
        exit();

    This works fine when i run it on my local web server (XAMPP). But, when i upload the script to the live server, i get the following errors instead:

    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>38</b><br />
    <br />
    <b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>38</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>39</b><br />
    <br />
    <b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>39</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>40</b><br />
    <br />
    <b>Warning</b>: imagefilledrectangle(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>40</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>41</b><br />
    <br />
    <b>Warning</b>: imagestring(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>41</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>44</b><br />
    <br />
    <b>Warning</b>: imagecolorallocate(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>44</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>47</b><br />
    <br />
    <b>Warning</b>: imagesx(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>47</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>48</b><br />
    <br />
    <b>Warning</b>: imagesy(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>48</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>49</b><br />
    <br />
    <b>Warning</b>: imageline(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>49</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>50</b><br />
    <br />
    <b>Warning</b>: imageline(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>50</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>51</b><br />
    <br />
    <b>Warning</b>: imageline(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>51</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>52</b><br />
    <br />
    <b>Warning</b>: imageline(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>52</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>58</b><br />
    <br />
    <b>Warning</b>: imagepng(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>58</b><br />
    <br />
    <b>Notice</b>: Undefined variable: im in <b>/home/username/domain.com/image.php</b> on line <b>64</b><br />
    <br />
    <b>Warning</b>: imagedestroy(): supplied argument is not a valid Image resource in <b>/home/username/domain.com/image.php</b> on line <b>64</b><br />
    This behaviour was only found in Internet Explorer 8 (don't know about older version of the IE).

    On firefox, it says the following:

    The image “http://domain.com/image.php?ID=1bH58...0&H=100” cannot be displayed, because it contains errors.
    What am i doing wrong here?
    Last edited by latheesan; 09-20-2009 at 03:19 AM.

  2. #2
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    I have got this error myself in one of my previous project..

    The problem seems to be with the function imagecreatetruecolor(), when there is gd2 installed on server ( not sure about this )

    Read this page http://us.php.net/manual/en/function...etruecolor.php. Also, compare the php configuration of both machines and find whats missing with GD.

  3. #3
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762
    My local test server (XAMPP) is running PHP Version 5.2.9

    and it's configured like so:

    cscript /nologo configure.js "--enable-snapshot-build" "--enable-debug-pack" "--with-snapshot-template=d:\php-sdk\snap_5_2\vc6\x86\template" "--with-php-build=d:\php-sdk\snap_5_2\vc6\x86\php_build" "--with-pdo-oci=D:\php-sdk\oracle\instantclient10\sdk,shared" "--with-oci8=D:\php-sdk\oracle\instantclient10\sdk,shared"
    with GD: http://i33.tinypic.com/27ww32x.png

    ------------------

    My live server is running PHP Version 5.2.6

    and it's configured like so:

    './configure' '--build=i686-redhat-linux-gnu' '--host=i686-redhat-linux-gnu' '--target=i386-redhat-linux-gnu' '--program-prefix=' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/usr/com' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--cache-file=../config.cache' '--with-libdir=lib' '--with-config-file-path=/etc' '--with-config-file-scan-dir=/etc/php.d' '--disable-debug' '--with-pic' '--disable-rpath' '--without-pear' '--with-bz2' '--with-curl' '--with-exec-dir=/usr/bin' '--with-freetype-dir=/usr' '--with-png-dir=/usr' '--with-xpm-dir=/usr' '--enable-gd-native-ttf' '--with-t1lib=/usr' '--without-gdbm' '--with-gettext' '--with-gmp' '--with-iconv' '--with-jpeg-dir=/usr' '--with-openssl' '--with-png' '--with-expat-dir=/usr' '--with-pcre-regex=/usr' '--with-zlib' '--with-layout=GNU' '--enable-exif' '--enable-ftp' '--enable-magic-quotes' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-sysvmsg' '--enable-track-vars' '--enable-trans-sid' '--enable-yp' '--enable-wddx' '--with-kerberos' '--enable-ucd-snmp-hack' '--with-unixODBC=shared,/usr' '--enable-memory-limit' '--enable-shmop' '--enable-calendar' '--enable-dbx' '--enable-dio' '--without-mime-magic' '--without-sqlite' '--with-libxml-dir=/usr' '--with-xml' '--with-system-tzdata' '--with-apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba' '--without-unixODBC' '--disable-pdo' '--disable-xmlreader' '--disable-xmlwriter' '--disable-json' '--without-pspell'
    with GD: http://i33.tinypic.com/16c98p3.png

    ------------------

    so, what's my live server missing?

  4. #4
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    apxs2=/usr/sbin/apxs' '--without-mysql' '--without-gd' '--without-odbc' '--disable-dom' '--disable-dba'
    live server missing gd itself?

  5. #5
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    Try a small script like this in your live server and check how it goes..

    Code:
    <?php
    header ('Content-type: image/png');
    $im = @imagecreatetruecolor(120, 20)
          or die('Cannot Initialize new GD image stream');
    $text_color = imagecolorallocate($im, 233, 14, 91);
    imagestring($im, 1, 5, 5,  'A Simple Text String', $text_color);
    imagepng($im);
    imagedestroy($im);
    ?>

  6. #6
    Join Date
    Jan 2005
    Location
    UK, London
    Posts
    762
    GD is installed and working fine though -> http://infinite-studio.com/dev/test/gd.php

  7. #7
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    $im = imagecreatetruecolor($im_width, $im_height);
    is it returning false at this line?

  8. #8
    Join Date
    Mar 2009
    Location
    Gods Own Country
    Posts
    681
    you might be having "display_errors" setting of PHP turned on in the live server. Try turning it off.

  9. #9
    Join Date
    Apr 2009
    Location
    Pittsburgh, Pennsylvania
    Posts
    582
    error_reporting(0); and it will work, your php.ini on your live server has display warnings

Similar Threads

  1. Using images from movies on a film site (copyright issues)
    By DungeonQ in forum Web Design and Content
    Replies: 1
    Last Post: 07-17-2009, 03:18 AM
  2. [request] Asp coder to resize images dynamically
    By redihot.com in forum Employment / Job Offers
    Replies: 1
    Last Post: 11-30-2006, 12:17 PM
  3. Can Flash Links Be Generated Dynamically?
    By Barti1987 in forum Programming Discussion
    Replies: 3
    Last Post: 07-14-2004, 12:51 PM
  4. copyright issues about images
    By Immolatus in forum Running a Web Hosting Business
    Replies: 14
    Last Post: 12-31-2003, 07:06 PM
  5. Dynamically generated page menu in PHP
    By Reptilian Feline in forum Programming Discussion
    Replies: 2
    Last Post: 03-25-2003, 04:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •