hello, i am using a function from http://www.nstoia.com/toh/imageresize.php to resize images... you are supposed to specify the path of the original file and then the path where it is saved...also the original and the name of the new file... in the function they append the original name to the original path and they append the saved name to the saved path...
i first set this up to have my script take an already uploaded image at it's regular size and overwrite it with a smaller resized image... this was making everything slowww.... i want to be able to resize them before they are uploaded to the server
i commented out the appended file names in the variables that show the paths... i tried to just use
$_FILES['Filedata']['tmp_name']
as the original directory and new directory so it just resizes it and continues to upload.... everything goes through but i end up with black thumbnails? why is this...
here is the function
////////////////////////////////////
////THUMBNAIL CREATOR
////////////////////////////////////
function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) {
$s_path = trim($s_path);
$o_path = trim($o_path);
$save = $s_path; //. $save;
$file = $o_path; //. $file;
$ext = strtolower(end(explode('.',$save)));
list($width, $height) = getimagesize($file) ;
if(($width>$t_w) OR ($height>$t_h)) {
$r1 = $t_w/$width;
$r2 = $t_h/$height;
if($r1<$r2) {
$size = $t_w/$width;
}else{
$size = $t_h/$height;
}
}else{
$size=1;
}
$modwidth = $width * $size;
$modheight = $height * $size;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
switch ($ext) {
case 'jpg':
case 'jpeg':
$image = imagecreatefromjpeg($file) ;
break;
case 'gif':
$image = imagecreatefromgif($file) ;
break;
case 'png':
$image = imagecreatefrompng($file) ;
break;
}
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
return;
}
here is my upload script:
<?php
session_id($_REQUEST['session_name']);
session_start();
include("../scripts/functions.php");
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
/////resize////
$file = "";
$save = "";
$t_w = 720;
$t_h = 720;
$o_path = $tempFile;
$s_path = $tempFile;
Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path);
////continue to upload
$targetPath = $_SERVER['DOCUMENT_ROOT'] . '/uploadify' . $_REQUEST['folder'] . '/' ;
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$ext = pathinfo($_FILES['Filedata']['name'], PATHINFO_EXTENSION); //figures out the extension
$newFileName = md5($tempFile).'.'.$ext; //generates random filename, then adds the file extension
$targetFile = str_replace('//','/',$targetPath) . $newFileName;
// $fileTypes = str_replace('*.','',$_REQUEST['fileext']);
// $fileTypes = str_replace(';','|',$fileTypes);
// $typesArray = split('\|',$fileTypes);
// $fileParts = pathinfo($_FILES['Filedata']['name']);
// if (in_array($fileParts['extension'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/',$targetPath), 0755, true);
if ($newFileName)
echo $newFileName;
else // Required to trigger onComplete function on Mac OSX
echo '1';
move_uploaded_file($tempFile,$targetFile);
echo "1";
// } else {
//
echo 'Invalid file type.';
// }
}
$_SESSION['img_name'][] = $newFileName;
?>