I'm trying to resize an uploaded image, but nothing happens (no file saved in 'large'). Can someone please tell me what I'm doing wrong?
list($width, $height, $type, $attr) = getimagesize("pictures/upload/".$file);
if($width > $height)
{
// resize image in 'upload' and save in 'large'
$i = "pictures/upload/".$file;
$new_width = 500;
$p = "pictures/large/";
$nn = $file;
$img = imagecreatefromjpeg("$i"); // Create a new image from file or URL
$old_width = imagesx($img); // Get image width
$old_height = imagesy($img); // Get image height
$scale = $new_width/$old_width;
$new_height = ceil($old_height*$scale); // Round fractions up
$newimg = imagecreate($new_width,$new_height); // Create a new palette based image
imagecopyresized($newimg,$img,0,0,0,0,$new_width,$new_height,$old_width,$old_height); // Copy and resize part of an image
imagejpeg($newimg, $p.$nn); // Output image to browser or file
}
else
{
// resize image in 'upload' and save in 'large'
$i = "pictures/upload/".$file;
$new_height = 500;
$p = "pictures/large/";
$nn = $file;
$img = imagecreatefromjpeg("$i"); // Create a new image from file or URL
$old_width = imagesx($img); // Get image width
$old_height = imagesy($img); // Get image height
$scale = $new_height/$old_height;
$new_width = ceil($old_width*$scale); // Round fractions up
$newimg = imagecreate($new_width,$new_height); // Create a new palette based image
imagecopyresized($newimg,$img,0,0,0,0,$new_width,$new_height,$old_width,$old_height); // Copy and resize part of an image
imagejpeg($newimg, $p.$nn); // Output image to browser or file
}