Interesting Image Problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

This one's been puzzling me for a while - I can only think it must be a
bug in PHP 5.1.4 (which is what I'm running).  I'm pretty sure it does
the same thing in PHP 4.  Is it a 'feature' I'm not aware of?

What I want is an image uploading program, which automatically saves a
fullsize version of the image, a thumbnail, and resizes the image
itself so it is no more than 400x400.  So - three copies of the image:

Original image (resized)
Copy of original image (fullsize)
Thumbnail (100x100)

I then wanted to display the original image to show it had been
uploaded correctly.

I wrote a class that does this, but it wasn't working correctly.  It
created all three images correctly, but when I output the original
image (which I had resized) it kept overwriting the fullsize image with
the resized image.  I tracked the bug down to the header() call.

Here is a test page of what I want to do - to make sure it wasn't my
class being weird, I wrote this:


//    get the original image details etc
    $image_path = "E:\Eclipse\htdocs\core\outlineb.gif";

    $im = imagecreatefromgif($image_path);

    $tmp = getimagesize($image_path);
    $width = $tmp[0];
    $height = $tmp[1];

//    create the second image
    $new_image_path = str_replace(".","_fullsize.",$image_path);

    $im_two = imagecreatefromgif($new_image_path);


//    resize the original image
    $im_resized = imagecreatetruecolor(100,100);

//    save the resized image

//    show the resized image
    #header("content-type: image/gif");


You will see two commented lines.  I tried destroying the resource
linking to the fullsize image before outputting the original image, but
that didn't work.

The second comment is the fascinating one.  If you comment out the
header call, the three images are left resized correctly, and the
browser displays gobbldegook (obviously).

Uncomment the header call and the image is displayed correctly, but the
second image is overwritten.  What's up with the header call?  What is
making PHP do this?



Re: Interesting Image Problem

Mr Fred wrote:
Quoted text here. Click to load it

But this is exactly what you wrote:

Quoted text here. Click to load it

First, you create $im from $image_path, then you save $im_resized to
$image_path instead of saving it to $new_image_path.  Rewrite the last

imagegif($im_resized, $new_image_path);


Re: Interesting Image Problem


Thanks for your comments.

The purpose of the script is to save the original image as
image_fullsize, and then resize the original image so it is no bigger
than 400x400 (or whatever).

The reason is this:  on a website photo gallery, I want three images: a
thumbnail, a 400x400 max. image, and the fullsize image.

So the script saves the original image as image_fullsize, then resizes
the original image and saves it.

What happens though, is that the fullsize image gets resized as well -
but ONLY if you call the header() function.


Site Timeline