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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.