Skip to content

Instantly share code, notes, and snippets.

@aslamdoctor
Created January 19, 2012 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aslamdoctor/1640168 to your computer and use it in GitHub Desktop.
Save aslamdoctor/1640168 to your computer and use it in GitHub Desktop.
Image Resizing based on Width & Height
<?php
function imageRestrict($image, $maxwidth, $maxheight) {
list($width,$height) = getimagesize($image);
if ($width > $maxwidth) {
$newheight = $maxwidth/$width * $height;
if($newheight > $maxheight){
$maxwidth = ($maxheight * $maxwidth)/$newheight;
$newheight = $maxheight;
}
return '<img src="'.$image.'" width="'.$maxwidth.'" height="'.$newheight.'">';
}
else {
return '<img src="'.$image.'" width="'.$width.'" height="'.$height.'">';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment