jnull Posted November 25, 2008 Posted November 25, 2008 Looking for a solution that I can place into my PHP pages that enables someone uploading an image file and also resizes that file to my desired sizes ... one a thumbnail, and two a larger image size. Any suggestions on what would work? Prefer a packaged solution that I could plug into my PHP pages, or a Java applet. Quote
TCH-Bruce Posted November 25, 2008 Posted November 25, 2008 I would recommend checking out hotscripts.com I'm sure you will find a script there to your liking. Most gallery type scripts support this. Quote
jnull Posted November 25, 2008 Author Posted November 25, 2008 Been browsing several. I am actually looking for something a bit more robust than scripts such as an off the shelf solution. Will keep looking and if anything comes to mind please don't hesitate to send up a flag. Thanx and have a wonderful Thanksgiving! Quote
OJB Posted November 25, 2008 Posted November 25, 2008 If you are a coder, then look into the GD library for PHP. It has image resizing methods built within it. Quote
jnull Posted November 26, 2008 Author Posted November 26, 2008 Thanx for the GD lead. Does anyone know if GD will work ok on TCH shared and/or managed dedicated servers? Quote
carbonize Posted December 3, 2008 Posted December 3, 2008 GD works fine and I can provide you with the resize code used in Lazarus if you wish which will also maintain transparency in PNG and GIF files. Quote
jnull Posted December 3, 2008 Author Posted December 3, 2008 Thanx much for your reply. The transparency side of things shouldn't be too much of an issue for the route we're taking, but if it does become so I'll be back in touch. Quote
carbonize Posted December 3, 2008 Posted December 3, 2008 (edited) Quick function for you (assuming you only want jpg images). >function image_Resize($source, $newwidth, $newHeight, $fileDestination, $newName) { $size = @getimagesize($source); if ($size[0] > $newWidth) { $newImgHeight = ($newWidth / $size[0]) * $size[1]; $newImgWidth = $newWidth; if ($newImgHeight > $newHeight) { $newImgWidth = ($newHeight / $newImgHeight) * $newImgWidth; $newImgHeight = $newHeight; } } elseif ($size[1] > $newHeight) { $newImgWidth = ($newHeight / $size[1]) * $size[0]; $newImgHeight = $newHeight; if ($newImgWidth > $newWidth) { $newImgHeight = ($newWidth / $newImgWidth) * $newImgHeight; $newImgWidth = $newWidth; } } else { $newImgWidth = $size[0]; $newImgHeight = $size[1]; } $newImgWidth = round($newImgWidth); $newImgHeight = round($newImgHeight); $im = imagecreatefromjpeg($source); $new_im = imagecreatetruecolor($newImgWidth,$newImgHeight); imagecopyresized($new_im,$im,0,0,0,0,$newImgWidth,$newImgHeight,$size[0],$size[1]); imagejpeg($new_im,$fileDestination.'/'.$newName,90); // Have set quality to 90 although 80 produces acceptible quality and smaller files. imagedestroy($new_im); } Just use that to create the resized copy and once you have made your thumbnail and other two images just use unlink($image) to delete the uploaded image. Oh yeah you will probably have to move the file from the temporary upload folder to one on your site before you can do anything with it. Edited December 3, 2008 by carbonize Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.