這個任務並不容易,因爲「重要」的部分可能並不總是在同一個地方。儘管如此,使用這樣的事情
$im = new imagick("c:\\temp\\523764_169105429888246_1540489537_n.jpg");
$imageprops = $im->getImageGeometry();
$width = $imageprops['width'];
$height = $imageprops['height'];
if($width > $height){
$newHeight = 80;
$newWidth = (80/$height) * $width;
}else{
$newWidth = 80;
$newHeight = (80/$width) * $height;
}
$im->resizeImage($newWidth,$newHeight, imagick::FILTER_LANCZOS, 0.9, true);
$im->cropImage (80,80,0,0);
$im->writeImage("D:\\xampp\\htdocs\\th_80x80_test.jpg");
echo '<img src="th_80x80_test.jpg">';
(測試)
應該工作。 cropImage參數(0和0)確定裁剪區域的左上角。因此,玩這些遊戲會給你留下不同的結果。
你得到了什麼錯誤?什麼是預期的輸出?什麼版本的PHP?是imagick安裝?更多細節請... –
不,這不是一個錯誤。 imagick工作正常。上面的腳本只會裁剪。我想首先調整大小,然後我想裁剪它,所以我錯過了第一步.. – newworroo
那麼,先調用'imageResize',然後... –