You are here: Interesting Image Problem « PHP Programming Language « IT news, forums, messages
Interesting Image Problem

Posted by Mr Fred on 09/08/06 12:51

Hi

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:

<?php

// 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);

copy($image_path,$new_image_path);
$im_two = imagecreatefromgif($new_image_path);

#imagedestroy($im_two);

// resize the original image
$im_resized = imagecreatetruecolor(100,100);
imagecopyresampled($im_resized,$im,0,0,0,0,100,100,$width,$height);

// save the resized image
imagegif($im_resized,$image_path);

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

?>

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?

Cheers

-bcg-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация