Created
March 14, 2019 01:37
-
-
Save justincarlson/f972f7ce88b89e031a016e3520e96237 to your computer and use it in GitHub Desktop.
PHP Imagick example image scaling to minimize blur and defects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ScaleToJpg($src,$width,$height,$dest) { | |
$im = new \Imagick($src); | |
$im->setImageCompression(\Imagick::COMPRESSION_JPEG); | |
$im->setImageCompressionQuality(100); | |
$im->stripImage(); | |
$im->setInterlaceScheme(\Imagick::INTERLACE_PLANE); | |
$size = $im->getImageGeometry(); | |
if($size['width'] >= $size['height']){ | |
if($size['width'] > $width){ | |
$im->resizeImage($width, 0, \Imagick::FILTER_SINC, 1); | |
} | |
} else{ | |
if($size['height'] > $height){ | |
$im->resizeImage(0, $height, \Imagick::FILTER_SINC, 1); | |
} | |
} | |
$im->writeimage($dest); | |
$im->clear(); | |
$im->destroy(); | |
$im = null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment