Create a thumb from uploaded image

Check out how to quickly create a thumb from uploaded image.

I assume that the Thumbnailer.php file is located in the same directory as the script below. If not change include path accordingly.

This example script will create a 120x90px Thumbnail for every uploaded image.

<?php
// create callback function
// which defines how to handle uploaded image
function callb(& $thumb) {
    
// resize image to 120x90px, round its corners and save
    // to any directory under same filename
    
$thumb->thumbFixed(120,90)->round()->save('thumbs/'.$thumb->filename);
}

// call upload helper, first parameter refers to the file upload field name
// example html
// <input type="file" name="upload_name" />

// always use try-catch statement to catch errors
try {
    
Thumbnailer::upload('upload_name''callb');
}
catch (
ThumbnailerException $e) {
    die(
"Error number ".$e->getCode()." occured: ".$e->getMessage());
}

?>