3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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(); }
Output for 4.3.0 - 7.1.0