Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- Interesting Image Problem
September 8, 2006, 12:51 pm
rate this thread
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)
I then wanted to display the original image to show it had been
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;
$height = $tmp;
// 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
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
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.
- » Getting the HTTP response code that is sent via a cell phone
- — Previous thread in » PHP Scripting Forum