Does anyone know of any image re-sizing scripts that allow the user to upload an image which is then resized and stored on the server. Also need it to be proportional and have the ability to set max height/width sizes. Thanks
You can do it fairly easily yourself, what I do is upload to a temp folder, resample and then move to the correct folder I can probably fish out something from the CMS if you need it
I usually use ASPUpload and ASPJpeg for jobs like this although I've been dabbling locally with a drop-in asp.net script which does the resizing just as well. If you've only a couple of images per page, you can allow users to upload quite big images and then resize them dynamically without increasing either server load or page load speed too much.
PHP: function fileextension($Filename) { $ext1 = explode(".", $Filename); $ext3 = count($ext1); $ext2 = $ext3 - 1; $Ext = $ext1[$ext2]; return $Ext; } // Where the file is going to be placed, temp directory for manipulation $target_path = "../temp/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $_FILES['uploadedfile']['tmp_name']; $target_path = "../temp/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { // Set a maximum height and width $width = $Imgw; $height = $Imgh; // Get new dimensions list($width_orig, $height_orig) = getimagesize($target_path); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig; } else { $height = $width/$ratio_orig; } $Ext = strtolower(fileextension($target_path)); // Grab new image switch ($Ext) { case "gif" : $image_t = imagecreate($width, $height); break; case "jpg" : $image_t = imagecreatetruecolor($width, $height); break; case "png" : $image_t = imagecreatetruecolortransparent($width, $height); break; } switch ($Ext) { case "gif" : $imagelarge = imagecreatefromgif($target_path); break; case "jpg" : $imagelarge = imagecreatefromjpeg($target_path); break; case "png" : $imagelarge = imagecreatefrompng($target_path); break; } // Create with new dimensions imagecopyresampled($image_t, $imagelarge, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); $target_path5 = "../images/"; $newName2 = $_FILES['uploadedfile']['name']; $water = $target_path5 . $newName; // Output switch ($Ext) { case "gif" : imagegif($image_t, $water, 75); break; case "jpg" : imagejpeg($image_t, $water, 75); break; case "png" : imagepng($image_t, $water, 0); break; } // Then delete temp file $imagedir = "../temp/"; unlink($imagedir . $newName2); $Imageu = ( $_FILES['uploadedfile']['name'] ); } else { echo "Error Uploading Image"; } To get you started
It doesn't seen to upload the file into the temp folder at all. I have checked that folder permissions are set correctly but it just doesn't upload the file when submitted via html form.
HTML: <body> <form enctype='multipart/form-data' name="imagesize" action="do.imageresize.php" method="POST"> <input name="file" type="file" /> <input type="submit" name="" value="submit" /> </form> </body> </html> PHP: <?phpfunction fileextension($Filename) {$ext1 = explode(".", $Filename);$ext3 = count($ext1);$ext2 = $ext3 - 1;$Ext = $ext1[$ext2];return $Ext;}// Where the file is going to be placed, temp directory for manipulation$target_path = "temp/";/* Add the original filename to our target path.Result is "uploads/filename.extension" */$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);$_FILES['uploadedfile']['tmp_name'];$target_path = "temp/";$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {// Set a maximum height and width$width = $Imgw;$height = $Imgh;// Get new dimensionslist($width_orig, $height_orig) = getimagesize($target_path);$ratio_orig = $width_orig/$height_orig;if ($width/$height > $ratio_orig) { $width = $height*$ratio_orig;} else { $height = $width/$ratio_orig;}$Ext = strtolower(fileextension($target_path));// Grab new imageswitch ($Ext) {case "gif" :$image_t = imagecreate($width, $height);break;case "jpg" :$image_t = imagecreatetruecolor($width, $height);break;case "png" :$image_t = imagecreatetruecolortransparent($width, $height);break;}switch ($Ext) {case "gif" :$imagelarge = imagecreatefromgif($target_path);break;case "jpg" :$imagelarge = imagecreatefromjpeg($target_path);break;case "png" :$imagelarge = imagecreatefrompng($target_path);break;}// Create with new dimensionsimagecopyresampled($image_t, $imagelarge, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);$target_path5 = "images/logos/";$newName2 = $_FILES['uploadedfile']['name'];$water = $target_path5 . $newName;// Outputswitch ($Ext) {case "gif" :imagegif($image_t, $water, 75);break;case "jpg" :imagejpeg($image_t, $water, 75);break;case "png" :imagepng($image_t, $water, 0);break;}// Then delete temp file $imagedir = "temp/"; unlink($imagedir . $newName2); $Imageu = ( $_FILES['uploadedfile']['name'] );}else { echo "Error Uploading Image"; }?>
You need to change either the form or PHP code for the field names to match, it's called "file" on the form and "uploadedfile" on the script At the moment they are just ignoring each other
You also need to define the image dimensions, either in the PHP, or pass them from the form and define them from that