Created
June 13, 2012 22:09
-
-
Save jlleblanc/2926803 to your computer and use it in GitHub Desktop.
Using JImage to create square profile pictures in two sizes, regardless of the original's orientation
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 | |
$image = new JImage('/path/to/original.jpg'); | |
$height = $image->getHeight(); | |
$width = $image->getWidth(); | |
if ($height > $width) { | |
$crop_square = $width; | |
$crop_top = ($height - $width) / 2; | |
$crop_left = 0; | |
} else { | |
$crop_square = $height; | |
$crop_top = 0; | |
$crop_left = ($width - $height) / 2; | |
} | |
$image = $image->crop($crop_square, $crop_square, $crop_left, $crop_top, false); | |
$small = $image->resize(48, 48); | |
$large = $image->resize(160, 160); | |
$small->toFile('/path/to/small.jpg'); | |
$large->toFile('/path/to/large.jpg'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Joseph how would this be used with JImage in 3.4.x ? I'm trying to find a way to display thumbnails for photographs in equally sized thumbs.yet if possible maintain equal height