Last active
December 22, 2015 00:57
-
-
Save bobmagicii/21ed918a4c093c54d1f1 to your computer and use it in GitHub Desktop.
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 | |
class ImageEditor { | |
static public function | |
MakeImageSquare(Imagick $Image, int $Square): | |
Imagick { | |
// $Image->CropThumbnailImage($Square,$Square); | |
// this method has a terrible habit of breaking every 3rd release. | |
// i am unsure if it is the php extension or imagemagick itself so | |
// whatevs. these other ones have yet to let me down. | |
$IW = $Image->GetImageWidth(); | |
$IH = $Image->GetImageHeight(); | |
// determine which axis to ratio against and scale to the required size. | |
if($IH > $IW) | |
$Image->ScaleImage( | |
$Square, | |
(ceil(($Square*$IH)/$IW)), | |
true | |
); | |
else | |
$Image->ScaleImage( | |
(ceil(($Square*$IW)/$IH)), | |
$Square, | |
true | |
); | |
// then crop off the rest to make the square. | |
$Image->CropImage( | |
$Square, | |
$Square, | |
(($IW/2)-($Square/2)), | |
(($IH/2)-($Square/2)) | |
); | |
return $Image; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment