Return to Snippet

Revision: 4787
at January 21, 2008 01:19 by dmlanger


Initial Code
function sizeme($img){
	$maxx=400;
    $maxy=300;
	list($width,$height)=getimagesize($img);
    if($width>$maxx){
        $newwidth = $maxx;
        $newheight = round($newwidth/$width*$height);
    } else {
        $newwidth=$width;
        $newheight=$height;
    }
	if($newheight>$maxy){
    	$newheight1=$maxy;
		$newwidth1=round($newheight1/$newheight*$newwidth);
	} else {
		$newheight1=$newheight;
		$newwidth1=$newwidth;
	}
	$out=array('width'=>$newwidth1,"height"=>$newheight1);
	return $out;
}

Initial URL


Initial Description
This function will return the height and width of an image that will change if the height/width is greater than the maximum supplied width and height.

Initial Title
Image Size Restrainer

Initial Tags
resize, image

Initial Language
PHP