Skip to content

Instantly share code, notes, and snippets.

@badsyntax
Created August 18, 2010 15:52
Show Gist options
  • Save badsyntax/535216 to your computer and use it in GitHub Desktop.
Save badsyntax/535216 to your computer and use it in GitHub Desktop.
<?php
$crop = '';
if ($image_width / $image_height > $width / $height) {
$crop .= ' -resize "x'.$height.'"';
$resized_w = ($height / $image_height) * $image_width;
$crop .= ' -crop "'.$width.'x'.$height.'+'.round(($resized_w - $width) / 2).'+0" +repage';
} else {
$crop .= ' -resize "' . $width . 'x"';
$resized_h = ($width / $image_width) * $image_height;
$crop .= ' -crop "'.$width.'x'.$height.'+0+'.round(($resized_h - $height) / 2).'" +repage';
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment