Today’s example is about making pretty thumbnails by combining a drop-in shadow with round corners.

The image is first scaled down to create a thumbnail. Imagick::thumbnailImage also strips all the associated profiles to make the image optimal to use in web applications.

The next step is to round the corners of the image. This is pretty trivial task but you should keep in mind that usually larger x and y rounding values give the optimal results when rounding the corners of a larger image. Generally it is pretty easy to find the suitable values by poking around with the parameters and making a formula out of it.

The final step is to create the drop-in shadow and composite the thumbnail over it. I use compositeImage in this example because Imagick::shadowImage creates only the shadow.

  1. <?php
  2.  
  3. /* Read the image into the object */
  4. $im = new Imagick( 'strawberry.png' );
  5.  
  6. /* Make the image a little smaller, maintain aspect ratio */
  7. $im->thumbnailImage( 200, null );
  8.  
  9. /* Round corners, web 2.0! */
  10. $im->roundCorners( 5, 5 );
  11.  
  12. /* Clone the current object */
  13. $shadow = $im->clone();
  14.  
  15. /* Set image background color to black
  16.         (this is the color of the shadow) */
  17. $shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
  18.  
  19. /* Create the shadow */
  20. $shadow->shadowImage( 80, 3, 5, 5 );
  21.  
  22. /* Imagick::shadowImage only creates the shadow.
  23.         That is why the original image is composited over it */
  24. $shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 );
  25.  
  26. /* Display the image */
  27. header( "Content-Type: image/png" );
  28. echo $shadow;
  29.  
  30. ?>

Once again, the original image:

strawberry

And the results:

shadow

P.S. Leave your ideas for new examples here.