Page 1 of 1

creating image thumbs easily

Posted: Tue Apr 14, 2009 5:25 am
by leeandrews78
we start with downloading the thumbnailer class from http://www.freelogic.pl/thumbnailer/ , then including the file and doin as follows:

Code: Select all

 
// create simple square thumb for every image we want
// with 100px width and height
 
$th=new Thumbnailer('some_photo.jpg');
$th->thumbSquare(100)->save('thumb_some_photo.jpg');
 
or we could create a thumb with any size we want using the fixed size method

Code: Select all

 
// 120px wide, 80px tall
 
$th=new Thumbnailer('any_photo.jpg');
$th->thumbFixed(120,80)->save('mythumb.jpg');
 
looks easy.. let say we have 200 photos from our camera - we want to process this directory and put those photos to our gallery:

Code: Select all

 
// creating callback function for batch mode
function callback(& $thumb) {
   // create symmetric photos (ratio will be 1:1)
   // (640px means, the larger width or height will have at max 640px)
   $thumb->thumbSymmetric(640)->save('/galleries/holiday_gallery/' . $thumb->getFilename());
 
   // create its thumb
   $thumb->thumbSquare(100)->save('/galleries/holiday_gallery/thumb_' . $thumb->getFilename());
}
 
// run batch mode
Thumbnailer::batch('callback', '/directory/with/photos/from/camera/');
 
very easy.