Results 1 to 2 of 2

Thread: Trouble with header function using php gd library

  1. #1
    Join Date
    Feb 2010
    Posts
    7

    Trouble with header function using php gd library

    Hi,

    I'm pretty new to php script writing and I have a funny feeling this is something quite simple but, I have a problem when I try to create an image. It's just a simple script to get a file from the server and resize it. I got most of the code from another website. Here is the code:


    <html>
    <body>
    <?php
    // Create source image and dimension.
    $src_img = imagecreatefrompng('mouse.png');
    $srcsize = getimagesize('mouse.png');
    $dest_x = 200;
    $dest_y = (200 / $srcsize[0]) * $srcsize[1];
    $dst_img = imagecreatetruecolor($dest_x, $dest_y);

    // Resize image
    imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);

    // Output image
    header("content-type: image/png");
    imagepng($dst_img);

    // Destroy images
    imagedestroy($src_img);
    imagedestroy($dst_img);
    ?>
    </body>
    </html>


    In firefox it says that the image could not be displayed because it contains errors. If I comment out the header it displays the raw file (A bunch of meaningless characters). I'm running WAMPServer Version 2.1, and when I run phpinfo() it says that everything to do with gd is enabled. Any thoughts?

    Thanks for your help!

  2. #2
    Join Date
    Feb 2010
    Posts
    7

    Solution

    I found the problem. The text editor that I was using for my php script had inserted some symbols before the <?php of the script and so it was corrupting the image. It's working nicely now. Thanks anyway.

Similar Threads

  1. Javascript function call in a php function problem
    By iuliser in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 15 Nov 2010, 06:10 AM
  2. trouble creating a simple header navbar!
    By lenglain in forum Web Design, HTML Reference and CSS
    Replies: 1
    Last Post: 05 Aug 2010, 07:50 PM
  3. Trouble Formatting Header
    By dd_massacre in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 20 May 2010, 07:32 PM
  4. Having trouble with "submit" button php function
    By TWyPGn in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 15 Jun 2009, 08:41 AM
  5. trouble with library items
    By mackieinva in forum Web Design, HTML Reference and CSS
    Replies: 0
    Last Post: 16 Feb 2009, 12:52 PM

Tags for this Thread

Posting Permissions

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