areaMax = $newValue; } public function setHeightMax($newValue) { $this->heightMax = $newValue; } public function setHeightMin($newValue) { $this->heightMin = $newValue; } public function setWidthMax($newValue) { $this->minWidthMax = $newValue; } public function setWidthMin($newValue) { $this->minWidthMin = $newValue; } /** * */ public function setValidImageTypes($array) { $this->validImageTypes = $array; } public function validate($file) { if (!is_file($file)) { throw new Exception('File not found.'); } $imageProperties = getimagesize($file); // Is it an image? if ($imageProperties === false) { return self::UNREADABLE; } // Is it an allowed image type? if ($validImageTypes) { $imageType = $imageProperties[2]; if (!in_array($imageType, $validImageTypes)) { return self::TYPEINVALID; } } $width = $imageProperties[0]; $height = $imageProperties[1]; // Does the file contain exactly 1 image? // From http://php.net/manual/en/function.getimagesize.php : "Some // formats may contain no image or may contain multiple images. In // these cases, getimagesize() might not be able to properly determine // the image size. getimagesize() will return zero for width and height // in these cases." if ($height === 0 && $width === 0) { return self::UNREADABLE; } // Wide enough? if ($this->widthMin && $width < $this->widthMin) { return self::SIZEINVALID; } // Tall enough? if ($this->heightMin && $height < $this->heightMin) { return self::SIZEINVALID; } // Too wide? if ($this->widthMax && $width > $this->widthMax) { return self::SIZEINVALID; } // Too tall? if ($this->heightMax && $height > $this->heightMax) { return self::SIZEINVALID; } // Too Big? $area = $height * $width; if ($this->areaMax && $area > $this->areaMax) { return self::SIZEINVALID; } return false; } }