我認為此函式無法如預期運作,已針對 imagemagick 版本 6.3.7 進行測試
如上所述,此函式會傳回具有固定高度和可變寬度的影像。以下是一個修正方法,可以傳回具有已定義尺寸的裁剪縮圖,而不會有尺寸變化。
<?php
$width = 160;
$height = 90;
$i = new Imagick("您的影像檔案");
$geo = $i->getImageGeometry();
if(($geo['width']/$width) < ($geo['height']/$height))
{
$i->cropImage($geo['width'], floor($height*$geo['width']/$width), 0, (($geo['height']-($height*$geo['width']/$width))/2));
}
else
{
$i->cropImage(ceil($width*$geo['height']/$height), $geo['height'], (($geo['width']-($width*$geo['height']/$height))/2), 0);
}
$i->ThumbnailImage($width,$height,true);
$i->setImageFormat("png");
header("Content-Type: image/png");
exit($i);
?>