note 37903 deleted from function.getimagesize by cmb

From: Date: Sun, 18 Dec 2016 09:45:00 +0000
Subject: note 37903 deleted from function.getimagesize by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208640@lists.php.net to get a copy of this message
Note Submitter: php (at) thejpster org uk ---- If you want to resize an image proportionally to fit within a given area, like I did, the following code might help you out. If either hscale or wscale are greater than 1 then that dimension is too big. If you then scale your image by the larger of the two values (hscale, wscale) then you guarantee that both dimensions will now fit in your specified area :) function makeImg($num) { global $hmax, $wmax; // max width and height $image = "somefile.jpg"; list($width, $height, $type, $attr) = getimagesize($image); $hscale = $height / $hmax; $wscale = $width / $wmax; if (($hscale > 1) || ($wscale > 1)) { $scale = ($hscale > $wscale)?$hscale:$wscale; } else { $scale = 1; } $newwidth = floor($width / $scale); $newheight= floor($height / $scale); return "<img width='$newwidth' height='$newheight' src='$image'><br>$image: $newwidth x $newheight : $width x $height"; }

« previous php.notes (#208640) next »