I have just finish creating a image resizing script and now I want it to resize an image when uploaded from a form.
I can't understand why I keep getting errors though. These are the errors:
Warning: Unable to access picture.jpg in /usr/local/psa/home/vhosts/reved-up.co.uk/httpdocs/test/sim_resize.php on line 9
Warning: getimagesize: Unable to open 'picture.jpg' for reading. in /usr/local/psa/home/vhosts/reved-up.co.uk/httpdocs/test/sim_resize.php on line 9
Warning: Division by zero in /usr/local/psa/home/vhosts/reved-up.co.uk/httpdocs/test/sim_resize.php on line 12
$file1 is the file upload field on the form. Here is the script:
<?
// resize function
function resize_jpg($img,$new_width,$quality){
// chmod ($img, 777);
$imagedata = getimagesize($img);
//calculate the aspect ratio for resizing
$aspectRat = (float)($imagedata[1] / $imagedata[0]);
//calculate new x/y size, maintaining original aspect ratio
if($imagedata[0] <= $new_width) {
return;
}
else {
$newY = $new_width * $aspectRat;
$newX = $new_width;
}
$destImg = imagecreate($newX, $newY);
$image = imagecreatefromjpeg($img);
imagecopyresized ($destImg, $image, 0, 0, 0, 0, $newX, $newY, $imagedata[0], $imagedata[1]);
imagejpeg($destImg, $img, $quality);
}
// call resize function resize_jpg(image name, new width, quality)
resize_jpg($file1_name,250,80);
?>
Please Help. Thank you