son.of.the.morning Posted December 7, 2011 Share Posted December 7, 2011 Alright guys, i have been looking for a simple script for this online to try get my head around it. I need a script thats is going to take an image and save the orginal file along with two modified files (small and medium thumbnail). I really cant get my head around the ones i have already seen so i was wondering if anyone had any advice or a link they can post me to that can help me. Quote Link to comment https://forums.phpfreaks.com/topic/252664-upload-and-resize-script/ Share on other sites More sharing options...
The Little Guy Posted December 7, 2011 Share Posted December 7, 2011 Here is some code I just wrote <?php function jpgThumb($orig_file, $save_file, $thumb_width, $quality = 75){ // Create a copy of the original image and save it into memory for later manipulation $main = imagecreatefromjpeg($orig_file); // Calculate the thumbnail's height/width based off the original images' height/width $info = getimagesize($orig_file); $width = $info[0]; $height = $info[1]; $new_height = $height * ($thumb_width / $width); // Create a blank thumbnail with our new height and width $thumb = imagecreatetruecolor($thumb_width, $new_height); // Resize the main image and place it on the thumbnail from the previous line. imagecopyresampled($thumb, $main, 0, 0, 0, 0, $thumb_width, $new_height, $width, $height); // Save the image thumbnail imagejpeg($thumb, $save_file, $quality); } jpgThumb("CapCom.jpg", "thumbs/CapCom.100.jpg", 100); jpgThumb("CapCom.jpg", "thumbs/CapCom.200.jpg", 200); ?> If you read though my comments above, it is fairly simple to create a thumb based on a jpeg. If you modify it, you can also work with png's (with alpha support) and gif's (with transparency support). Quote Link to comment https://forums.phpfreaks.com/topic/252664-upload-and-resize-script/#findComment-1295286 Share on other sites More sharing options...
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.