Ryan
Ryan

Reputation: 15250

How can I generate several thumbnails for a larger image?

Given a large image (let's say at least 1200x800px), how can I generate smaller centered square and scaled thumbnails?

I need to generate several thumbnails for this image:

  1. 300x300 square (centered, preferably)
  2. 100x100 square (centered, preferably)
  3. 600 max (width or height, scaled proportionally)
  4. 100 max (width or height, scaled proportionally)

Is there a linux or php library that will help accomplish this?

Sample Image: http://placehold.it/1200x800

Upvotes: 0

Views: 76

Answers (1)

drew010
drew010

Reputation: 69927

Check out PHP Thumbnailer. Simply create one thumbnail for each size you want.

Example Usage:

$thumb = PhpThumbFactory::create('/path/to/image.jpg');
$thumb->resize(100, 100);  // resize to 100x100
$thumb->save('/path/to/100x100.jpg');

Simply do that for each size you wish to save.

Check out the docs for more examples.

Upvotes: 1

Related Questions