473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Interesting Image Problem

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-

Sep 8 '06 #1
2 1315
NC
Mr Fred wrote:
>
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.
But this is exactly what you wrote:
$image_path = "E:\Eclipse\htdocs\core\outlineb.gif";
$im = imagecreatefromgif($image_path);
....
$new_image_path = str_replace(".","_fullsize.",$image_path);
....
imagegif($im_resized,$image_path);
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
line:

imagegif($im_resized, $new_image_path);

Cheers,
NC

Sep 8 '06 #2
Hi

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.

bcg

Sep 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ohaya | last post by:
Hi, We've been having a problem with one particular page that has a button on it, and a "tall" image (top-to-bottom). The button calls some simple Javascript to print the frame in which the...
3
by: George Hester | last post by:
This is in Microsoft Internet Explorer 5.5. I have one page with 20 thumbnail images in it. Clicking on the thumbnail image opens another page with the full image as its only content. The page...
0
by: Richard | last post by:
Considering the code below. Adapting this part of the code from meyerweb.com to my own use, I was playing around with some values and came up with an interesting result I like. Copy and paste...
3
by: CanyonJ | last post by:
I've been running into a frustrating problem for a while now. I use image.FromStream to open a tif, then perform some drawstring methods, and then save the file again. The tiffs are in 1 bit per...
5
by: Ross27 | last post by:
Imagine a table in Microsoft Sql Server 2000 named Pictures with three fields. A primary key ID(int), a Name(nvarchar) and a Picture(image) field. Lets put some records into the table. The first...
15
by: Anand Ganesh | last post by:
HI All, I have an Image. I want to clip a portion of it and copy to another image. How to do this? I know the bounding rectangle to clip. Any suggestions please. Thanks for your time and...
2
by: Andreas Viklund via DotNetMonster.com | last post by:
Hi! I am developing an application in ASP.NET that takes an image, that have been created with a digital camera or camera phone, and processes it, to get data from it. The image taken by the user...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
11
by: kimiraikkonen | last post by:
Hi there, I needed to use MouseOver event on Webbrowser which is NOT provided by webbrowser control natively(what a disappointment), so i decided to go with another route to simulate this like: ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.