Created
September 20, 2016 04:55
-
-
Save webdawe/cf40a0ca8b1d92a6083666a494dd7afd to your computer and use it in GitHub Desktop.
Imagick Resize
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
function imagickResize($uploadDir, $fileFrom, $fileTo, $newWidth, $newHeight) | |
{ | |
$thumb = new Imagick(); | |
$thumb->readImage($uploadDir. $fileFrom); | |
$dimensions = $thumb->getImageGeometry(); | |
$orginalWidth = $dimensions['width']; | |
$orginalHeight = $dimensions['height']; | |
$ratio = $orginalWidth/$orginalHeight; | |
if ($orginalWidth < $newWidth || $orginalHeight < $newHeight) | |
{ | |
return ''; | |
} | |
else if ($newWidth/$newHeight > $ratio) | |
{ | |
$newWidth = $newHeight * $ratio; | |
} | |
else | |
{ | |
$newHeight = $newWidth / $ratio; | |
} | |
$thumb->resizeImage($newWidth, $newHeight, Imagick::FILTER_LANCZOS,1); | |
$thumb->writeImage($uploadDir.$fileTo); | |
$thumb->clear(); | |
$thumb->destroy(); | |
return $fileTo; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment