Permalink
Browse files

Added validation rule to check image dimensions

  • Loading branch information...
1 parent f5e5133 commit a15222a6dc91dd8b22c99bb563b4e517fbe14754 @nCrazed nCrazed committed Jan 29, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 Model/Behavior/UploadBehavior.php
@@ -78,6 +78,27 @@ public function size($model, $check, $size) {
return $size >= $check['size'];
}
+ /**
+ * Check if the image fits within given dimensions
+ *
+ * @param array $check Array of data from the file that is been checked
+ * @param int $width Maximum width in pixels
+ * @param int $height Maximum height in pixels
+ * @return bool Return true if image fits withing given dimensions
+ * @access public
+ */
+ public function maxDimensions($model, $check, $width, $height) {
+ $check = array_shift($check);
+
+ if (isset($check['tmp_name']) && is_file($check['tmp_name'])) {
+ $info = $this->getimagesize($check['tmp_name']);
+
+ return ($info && $info[0] <= $width && $info[1] <= $height);
+ }
+
+ return false;
+ }
+
public function getFileMime($model, $file) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$info = finfo_file($finfo, $file);

0 comments on commit a15222a

Please sign in to comment.