<?php
function resizeImg($img, $width, $height, $path) {
$i = new Imagick($img);
$i->scaleImage($width, $height);
$gig = $i->getImageGeometry();
if(($gig['width']/$width) < ($gig['height']/$height)) {
$i->cropImage($gig['width'], floor($height * $gig['width'] / $width), 0, (($gig['height'] - ($height * $gig['width'] / $width)) / 2));
} else {
$i->cropImage(ceil($width * $gig['height'] / $height), $gig['height'], (($gig['width'] - ($width * $gig['height'] / $height)) / 2), 0);
}
$i->ThumbnailImage($width, $height,true);
$i->setImageFormat("jpeg");
$i->setImageCompressionQuality(90);
$i->writeImage($path);
return $i->getimage();
}
preferences:
27.49 ms | 402 KiB | 5 Q