Skip to content

Instantly share code, notes, and snippets.

@jlleblanc
Created June 13, 2012 22:09
Show Gist options
  • Save jlleblanc/2926803 to your computer and use it in GitHub Desktop.
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
<?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');
@N6REJ
Copy link

N6REJ commented Jan 4, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment