Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post

    PHP Image not working correctly

    I recently switched hosts and my image thing stopped working.

    http://cookyx.com/obj02/1.png

    I know my .htaccess works because I use /news/ and /profiles/ in it too. And yes I did CHMOD my directories to 777.

    See all that nonsense?

    here is the source

    PHP Code:
    <?php
    include "config.php";

    $id $_GET[id];
    $getx mysql_query("SELECT * FROM `members` WHERE `id` = '$id'") or die(mysql_error()); //get all the
    $user mysql_fetch_array($getx);



    // load the image from the file specified:
    $im imagecreatefrompng("images/compactstat.png");
    // if there's an error, stop processing the page:

    if(!$im)
    {
     die(
    "");
    }
    // define some colours to use with the image
    $yellow imagecolorallocate($im113113113);
    $black imagecolorallocate($im000);
    // get the width and the height of the image
    $width imagesx($im);
    $height imagesy($im);
    // draw a black rectangle across the bottom, say, 20 pixels of the image:

    // now we want to write in the centre of the rectangle:
    $font 8// store the int ID of the system font we're using in $font
    $text "$user[username]";
    $text2 "$user[cookies]"// store the text we're going to write in $text
    // calculate the left position of the text:
    $leftTextPos = ( $width imagefontwidth($font)*strlen($text) )/2;

    $namecon3 strlen($user[username]);
                    


    // finally, write the string:
    imagestring($im$font2722$text$yellow);
    imagestring($im$font7043$text2$yellow);
    imagestring($im2);
    // output the image
    // tell the browser what we're sending it



    header("Content-type: image/png");

    imagepng($im"images/compact2/{$_GET['id']}.png");
     
    header("Content-type: image/png");


    imagepng($im);
    // tidy up
    imagedestroy($im);

    ?>
    what is wrong?

    Nvm, I found out the problem myself.
    It was this line that caused the problem:
    PHP Code:
    imagestring($im2); 
    Last edited by UrbanTwitch; 12-02-2008 at 06:38 AM.
    Formerly MysticScript

    6+ years club

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    The errors are being recorded to you're screen. Because of the errors, you can't send the proper headers to display you're image. What you see is an ascii representation of the binary data within the file. Pretty neat eh?

    Anyway, you're imagestring is one thats killing it. This one:
    PHP Code:
    imagestring($im2); 

    The other one looks like its trying to write an image to an incorrect directory. Be more specific with it, try using an absolute path.

    Once those are fixed, the image should display again. You're last host probably had output buffering enabled, which would still allow you to send you're proper headers after the errors occured.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • Users who have thanked Fou-Lu for this post:

    UrbanTwitch (12-02-2008)

  • #3
    Regular Coder UrbanTwitch's Avatar
    Join Date
    Apr 2006
    Posts
    485
    Thanks
    44
    Thanked 1 Time in 1 Post
    haha yeah, thanks anyway Fou-Lu. What would the world do with out you? :P
    Formerly MysticScript

    6+ years club


  •  

    Posting Permissions

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