note 80656 deleted from function.getimagesize by cmb

From: Date: Sun, 18 Dec 2016 09:39:54 +0000
Subject: note 80656 deleted from function.getimagesize by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-208630@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- // 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;

« previous php.notes (#208630) next »