PDA

View Full Version : Image Pop-Up (Higher Res)


greens85
10-05-2007, 09:36 AM
Hi All,

I currently have a situation where an image is submitted through an upload form then automatically resized using php. Although that is exactly what i want to happen to the image i also want the user to be able to click on the image and for the image to open in a new pop up window at a higher resolution.

I was thinking the way to go about this might be javascript, although im unsure how it would be done as the image is submitted by the user and therefore isnt always going to be the same image? I think what i need to do to achieve this is when the image it submitted for the original image to be saved and then the thumbnail created, that way i can reference the original image in javascript. Is this possible???

Can anyone point me in the right direction to get started with this?

Thanks

mlseim
10-05-2007, 01:52 PM
When the original image is uploaded, that image gets saved into a directory,
but before that, you use PHP to create a "smaller" version of that and save
it in a different directory. So you have the same image (same filename) saved
into two directories ... one is the original, the other is the thumb (or smaller).

Also see this codingforums post ... author has a working script to make thumbs:
http://www.codingforums.com/showthread.php?t=125042

By keeping the filename the same in both directories, you can more easily
manage not only the references (for display and links), but also when you
want to delete it, the filenames are the same, just different directories.

greens85
10-05-2007, 02:02 PM
Is there a default where the original image is saved because ive tried the following code (the bit that is commented as STORE THE ORIGINAL IMAGE) to try and save it in a specific folder, i believe the rest of the code resizes and stores the thumbnail image.

?php

// This is the temporary file created by PHP
$uploadedfile = $_FILES['uploadfile']['tmp_name'];

// Create an Image from it
$src = imagecreatefromjpeg($uploadedfile);

//Store The Original Image
$filename2 = "images/dynamicimages/originalimages/".$_FILES['uploadedfile']['name'];
imagejpeg ($src, $filename2, 100);

// Capture the original size of the uploaded image
list($width,$height)=getimagesize($uploadedfile);

// Set the new width and height
$newwidth=251;
$newheight=($height/$width)*251;
$tmp=imagecreatetruecolor($newwidth,$newheight);

// Resize image and place it in $tmp variable
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

// Save the resized file to the server
$filename = "images/dynamicimages/". $_FILES['uploadfile']['name'];
imagejpeg($tmp,$filename,100);

imagedestroy($src);
imagedestroy($tmp);
?>

mlseim
10-05-2007, 04:34 PM
You're saying it doesn't store it?

But you also don't get any scripting errors?

Make sure this directory (originalimages/) has permissions set to 0777.
Maybe it's just not saving because of write permissions.