Here’s a few examples of how to thumbnail an image:

  1. <?php
  2.  
  3. /* Create new imagick object */
  4. $im = new imagick( 'mccurry.jpg' );
  5.  
  6. /* Clone the object for different types */
  7. $normal = $im->clone();
  8. $fit = $im->clone();
  9. $fixed = $im->clone();
  10. $crop = $im->clone();
  11.  
  12. /* Create a normal thumbnail 100x width, save dimensions */
  13. $normal->thumbnailImage( 100, null );
  14. $normal->writeImage( "normal_thumbnail.jpg" );
  15.  
  16. /* Create a fit thumbnail, both sides need to be smaller
  17.    than the given values, save dimensions */
  18. $fit->thumbnailImage( 100, 100, true );
  19. $fit->writeImage( "fit_thumbnail.jpg" );
  20.  
  21. /* Create a fixed size thumbnail, ignore dimensions */
  22. $fixed->thumbnailImage( 100, 100 );
  23. $fixed->writeImage( "fixed_thumbnail.jpg" );
  24.  
  25. /* Create a thumbnail, keep dimensions, crop overflowing parts */
  26. $crop->cropThumbnailImage( 100, 100 );
  27. $crop->writeImage( "crop_thumbnail.jpg" );
  28.  
  29. ?>

The example image is “Afghan Girl” by Steve McCurry. I’m hoping that this goes under fair use. I will remove this image from my blog if any of the copyright holders feels like I’m violating their rights.

Original image:

mccurry

Normal thumbnail:

normal

Fit thumbnail:

fit

Fixed size thumbnail:

fixed

Cropped thumbnail:

crop