Assuming your using http://pear.php.net/package/Image_Transform you can use this code to take an uploaded image and out put 2 scaled down images.
PHP Code:
$upload_file = basename($_FILES['uploadfile']['name']);
// create a file with just a 0 in it to keep track of uploads or don't and remove all instances of these 2 variables
$log_file = "num.txt";
$file_num = file_get_contents($log_file);
//those 2
$dir = "images/";
$thumb = "thumb/";
$output_format = ".jpg";
// set the directory for where the file file is to go
$uploaddir = "images/original/";
$file_name = basename($_FILES['uploadfile']['name']);
//set the path and file name for the move file
$file = $uploaddir . $file_name;
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) {
echo "Success";
require_once 'Image/Transform.php';
//
//create transform driver object
$it = Image_Transform::factory('GD');
if (PEAR::isError($it)) {
die($it->getMessage());
}
//load the original file
$ret = $it->load("$file");
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
//scale it to 100 pixels wide
$ret = $it->scaleByLength(100);
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
//save it into a different file
$ext = substr($file_name,strlen($file_name)-3,3);
$clear_ext = explode("." . $ext, $file_name);
$file_name = $clear_ext[0];
$ret = $it->save("$dir$custom$thumb$file_name" . "_file" . $file_num . $output_format);
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
//load the original file
$ret = $it->load("$file");
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
//scale it to 500px
$ret = $it->scaleByLength(500);
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
//save it into a different file
$ret = $it->save("$dir$custom$file_name" . "_file" . $file_num . $output_format);
if (PEAR::isError($ret)) {
die($ret->getMessage());
}
$file_num++;
file_put_contents($log_file, $file_num);
echo $file_num;
} else
{
echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)";
}
This is shortened down from a larger file. If this doesn't work and you have library installed post back and I'll check what part I cut out that you needed hah.
Bookmarks