...

View Full Version : combine image upload & image resize scripts



jamescover
10-02-2004, 01:21 PM
Uploads an image file from an HTML form:



<?php

$dir = "lists/images/";
$uploadfile = $dir . $_FILES["img"]["name"];



if (move_uploaded_file($_FILES["img"]["tmp_name"], $uploadfile)){

//when chmod-ing, remember $uploadfile includes $dir

chmod("/home/domain/www/www/path/to/images/$uploadfile", 0775);
echo "markup goes here";
}

?>


Creates a thumbnail from Original Image:


<?php

//resizes (dimensions & filesize) an image to create a thumbnail

$img = $_POST["oSel"];
$src = imagecreatefromjpeg($img);

// get current image size

$width = imagesx($src);
$height = imagesy($src);

$aspectRatio = 150/$height;

// resize image

$newWidth = abs($width * $aspectRatio);
$newHeight = abs($height * $aspectRatio);

//create new image

$newImg = imagecreatetruecolor($newWidth,$newHeight);

//save new image

imagecopyresampled ($newImg,$src,0,0,0,0,$newWidth,$newHeight,$width,$height);
imagejpeg($newImg,$img,90);
imagedestroy($newImg);

echo "markup goes here";

?>


I'd like to combine the above two scripts. Save one [fullsized] image to one directory, and save a thumbnail of the same image to another directory.

Any help is appreciated. Thanks!


-james

sir pannels
10-02-2004, 03:26 PM
hey James..

Have you considered only saving the big image and then generating the thumbnail on the file form the big one? save you space.

jamescover
10-03-2004, 06:28 AM
hey James..

Have you considered only saving the big image and then generating the thumbnail on the file form the big one? save you space.


Hi sir pannels...thanks, for responding.


Sorry, but I don't get your intended meaning. I don't want to resize the image using height and width attributes, if that's what you mean. I need to also reduce the file size, so I'd prefer to store one [fullsized] image in one directory, and another [thumbsized] image in another directory. I can currently do this with the above scripts, but I'd like to combine the 2 scripts, for a CMS, so that the user doesn't have to select the image twice. Clear as mud???

Thanks, again.




-james

jamescover
10-15-2004, 11:58 AM
oops...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum