Check Image Dimensions

Description: Checks to see if a given image meets specified image width and height dimensions.
Tested Platform: PHP 5
Language: PHP
// Check image file and make sure they are equal to width and height specified.
// Expects: Valid path to an image and optional image width/height as integers
// Returns: true or false

function checkImageDimensions($imageFilename = "", $imgWidth = 1, $imgHeight = 1) {
     if (!empty($imageFilename) && file_exists($imageFilename) && (!is_dir($imageFilename))) {
          list($width, $height, $type, $attr) = getimagesize($imageFilename);
		
          if (($width == $imgWidth) && ($height == $imgHeight)) {
               return true;
          }
     }
     return false;
}

Submitted: December 24, 2012

Return to the snippets listing