note 80656 added to function.getimagesize

From: Date: Mon, 28 Jan 2008 05:14:19 +0000
Subject: note 80656 added to function.getimagesize
Groups: php.notes 
Request: Send a blank email to php-notes+get-135449@lists.php.net to get a copy of this message
// A way to maintain Aspect Ratio // Here using standard aspect ratio of 4:3 for landscape and 3:4 for portrait. // example is 50% image resize //NewWidth = GivenHeight * (OriginalWidth / OriginalHeight) //NewHeight = GivenWidth * (OriginalHeight / OriginalWidth) $defaultImageWidth = 160; //your gallery image width $defaultImageHeight = 120; //your gallery image height $imageWidth = 462; // use getimagesize() to get image width $imageHeight = 432; // use getimagesize() to get image height if($imageWidth > $imageHeight) { // landscape image $newWidth = $defaultImageWidth; $newHeight = (int)($defaultImageWidth * $imageHeight / $imageWidth); if($newHeight > $defaultImageHeight) { $newHeight = $defaultImageHeight; $newWidth = (int)($defaultImageHeight * $imageWidth / $imageHeight); } } elseif ($imageHeight > $imageWidth) { // portrait image $newHeight = $defaultImageHeight; $newWidth = (int)($defaultImageHeight * $imageWidth / $imageHeight); if($newWidth > $defaultImageWidth) { $newWidth = $defaultImageWidth; $newHeight = (int)($defaultImageWidth * $imageHeight / $imageWidth); } } else { // square image $newWidth = $defaultImageWidth; $newHeight = $defaultImageHeight; } // here using Image Magick command line utility to resize image, OR you can use some other package. //@exec("/usr/local/bin/convert $sourceImageFilePath - -resize $newWidthx$newHeight\! $destinationImageFilePath"); echo '<b>New Width:</b>'.$newWidth; echo "<br>"; echo '<b>New Height:</b>'.$newHeight; ---- Server IP: 203.199.69.133 Probable Submitter: 203.129.203.66 ---- Manual Page -- http://www.php.net/manual/en/function.getimagesize.php Edit -- https://master.php.net/note/edit/80656 Del: integrated -- https://master.php.net/note/delete/80656/integrated Del: useless -- https://master.php.net/note/delete/80656/useless Del: bad code -- https://master.php.net/note/delete/80656/bad+code Del: spam -- https://master.php.net/note/delete/80656/spam Del: non-english -- https://master.php.net/note/delete/80656/non-english Del: in docs -- https://master.php.net/note/delete/80656/in+docs Del: other reasons-- https://master.php.net/note/delete/80656 Reject -- https://master.php.net/note/reject/80656 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#135449) next »