Imagick Thumbnail From Center
There are exactly 983,292,023,674 thumbnail scripts available on the internet. All do basically the same thing, take an image and resize it to a given size. Here we use a different approach by cutting out the center of the image and using that as a thumbnail. This makes for a more artistic thumbnail however, your mileage may vary if the subject of the image is not central. This may not be such a bad thing as it may pick up some additional aspect of the image, but depending on the image composition, may just pick up a black blob.
<?php
try
{
/*** image name ***/
$imgSrc = "flower.jpg";
/*** set the size of the thumbnails ***/
$thumb_width = 80;
$thumb_height = 80;
/*** a new imagick object ***/
$im = new Imagick($imgSrc);
/*** getting the image dimensions ***/
list($width, $height) = array_values($im->getImageGeometry());
$x=($width-$thumb_width)/2;
$y=($height-$thumb_height)/2;
/*** crop the image ***/
$im->cropImage($thumb_width, $thumb_height, $x, $y);
/*** set the header ***/
header( "Content-Type: image/{$im->getImageFormat()}" );
/*** show the thumbnail ***/
echo $im->getImageBlob();
}
catch (Exception $e)
{
echo $e->getMessage();
}
?>