Skip to content

Instantly share code, notes, and snippets.

@wishfoundry
Created November 21, 2012 17:34
Show Gist options
  • Save wishfoundry/4126316 to your computer and use it in GitHub Desktop.
Save wishfoundry/4126316 to your computer and use it in GitHub Desktop.
image resize
if ($image_w < $image_h)
{
//portrait
$height = $max_height;
$width = round( $height*($image_w/$image_h) );
}
if($image_w => $image_h)
{
//landscape
if($image_h < ($image_w/2))
{
//resize by width
$width = $max_width;
$height = round( $width*($image_h/$image_w) );
}
else
{
//resize by height
$height = $max_height;
$width = round( $height*($image_w/$image_h) );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment