scenarios
real life examples› Import camera photos to a gallery [go back]
<?php
require 'Thumbnailer.php';
// create callback function for batch mode purpose
function callback(& $thumb)
{
// get photo name
$name=$thumb->getFilename();
// resize photos to at max 640px
$thumb->thumbSymmetric(640)->save('/myGallery/holidays/'.$name);
// create cumstom 120x80px thumbs for those photos
// with a thumb_ prefix
$thumb->thumbFixed(120,80)->save('/myGallery/holidays/thumb_'.$name);
// save to database
mysql_query('insert into gallery_photos (gallery_id,name) values (1,'.$name.')');
}
// run batch mode using our callback function
// on our camera photos
Thumbnailer::batch('callback','/myDirectory/with/camera/photos/');
?>
› Process user uploaded photos [go back]
<?php
require 'Thumbnailer.php';
// create thumbnailer object
$th=new Thumbnailer($_FILES['fileField']['tmp_name']);
// resize photo to acceptable size if necessary
// then create a 80px square thumb and save both
// to specified directory
// create unique photo name
$name=md5(uniqid(mt_rand(),true)).'.jpg';
$photo_dir='/users/photos/'.$user_id.'/';
$th->thumbSymmetric(800)->save($photo_dir.$name);
$th->thumbSquare(80)->save($photo_dir.'thumb_'.$name);
// release memory
unset($th);
?>