Jump to content

Upload and resize script


son.of.the.morning

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/252664-upload-and-resize-script/
Share on other sites

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).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.