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.
- /* Read the image into the object */
- $im = new Imagick( 'strawberry.png' );
- /* Make the image a little smaller, maintain aspect ratio */
- $im->thumbnailImage( 200, null );
- /* Round corners, web 2.0! */
- $im->roundCorners( 5, 5 );
- /* Clone the current object */
- $shadow = $im->clone();
- /* Set image background color to black
- (this is the color of the shadow) */
- $shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
- /* Create the shadow */
- $shadow->shadowImage( 80, 3, 5, 5 );
- /* Imagick::shadowImage only creates the shadow.
- That is why the original image is composited over it */
- $shadow->compositeImage( $im, Imagick::COMPOSITE_OVER, 0, 0 );
- /* Display the image */
- header( "Content-Type: image/png" );
- echo $shadow;
Once again, the original image:
And the results:
P.S. Leave your ideas for new examples here.