Greetings I ahave been trying forever to get this image resize script to work ..
I get these errors
Warning: imagejpeg(): Unable to open 'photos/thumbs/C:\WINDOWS\php1D.tmp' for writing in e:\inetpub\wwwroot\foo.com\process_upload.php on line 62
I want to create 2 thumbnails in total ...
1.) the thumbnail created
max_width=200
max_height=200
2.) the second thumbnail created
max_width=90
max_height=90
Any help would be appreciated ..thanks so much
🙂
<?php
#-+ form variables +- #
//<input type='file' name ='filename'size ='22'></td>
//<input type='hidden' name='MAX_FILE_SIZE' value='100000'>
#-+ process form +- #
#-+ Directory where photos will be saved
$photos = "e:/\Inetpub/\wwwroot/\foo.com/\photos/";
#-+ Directory where the thumbnails will be saved
$thumbnails = "e:/\Inetpub/\wwwroot/\foo.com/photos/thumbs/";
if($filename==''){echo"No file Uploaded";
exit;
}
if($filename_size=='0'){echo"Uploaded file is zero lenght";
exit;
}
if(!is_uploaded_file($filename)){echo"We are watching ! ";
exit;
}
#-+ resize and set constraints
// first thumbnail
$max_width="200";
$max_height="200";
// second thumbnail
$tmax_width="200";
$tmax_height="200";
list($orig_width, $orig_height,$type,$attr) = getimagesize($filename);
$width = $orig_width;
$height = $orig_height;
if ($height > $max_height) {
$width = ($max_height / $height) * $width;
$height = $max_height;
}
if ($width > $max_width) {
$height = ($max_width / $width) * $height;
$width = $max_width;
}
#-+ get extention
#-+ Create a new temporary image
$canvas = imagecreate($width, $height);
$source = imagecreatefromjpeg($filename );
#-+ Copy and resize old image into new image ...Do it!
imagecopyresized($canvas, $source, 0, 0, 0, 0,$width, $height, $orig_width, $orig_height);
#-+ Save it!
copy($canvas,$thumbnails.$filename);
#-+ Show it !
imagejpeg($canvas,$thumbnails.$filename);
#-+ Print report
echo "Original dimensions: $orig_width x $orig_height<br>\n";
echo "Thumbnail dimensions: $width x $height<br>\n";
printf ("<a href=\"$photos.$filename\"><img src=\"$thumbnails.$filename\" ></a>");
?>