creating image thumbs easily

GD and GD2 are useful libraries for creating graphics on-the-fly. Discuss your PHP GD and GD2 scripts here.

Moderators: onion2k, General Moderators

Post Reply
leeandrews78
Forum Newbie
Posts: 2
Joined: Tue Apr 14, 2009 5:11 am

creating image thumbs easily

Post 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.
Post Reply