Skip to content

Commit

Permalink
2017-02-25 1511
Browse files Browse the repository at this point in the history
  • Loading branch information
allanmcarvalho committed Feb 25, 2017
1 parent df29cc7 commit fde0da8
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,28 @@ or
'message' => 'Must have the shortest height',
'provider' => 'upload'
]);

$validator
->add('file1', 'isThisWidth', [
'rule' => ['isThisWidth', 800],
'message' => 'Must have a width of 800px',
'provider' => 'upload'
]);

$validator
->add('file1', 'isThisHeight', [
'rule' => ['isThisHeight', 900],
'message' => 'Must have a height of 900px',
'provider' => 'upload'
]);

$validator
->add('file1', 'isThisWidthAndHeight', [
'rule' => ['isThisWidthAndHeight', 800, 900],
'message' => 'Must have a width of 800px and height of 900',
'provider' => 'upload'
]);

$validator
->add('file1', 'isThisAspectRatio', [
'rule' => ['isThisAspectRatio', 3, 4],
Expand Down
60 changes: 60 additions & 0 deletions src/Validation/Traits/ImageTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,66 @@ public static function isBelowMaxHeight($check, $height)

return $image->height() > $height ? false : true;
}

/**
* Check that the file has exact width requirement
*
* @param mixed $check Value to check
* @param int $height Height of Image
* @return bool Success
*/
public static function isThisWidth($check, $width)
{
if (!self::checkTmpFile($check))
{
return false;
}
$image = self::getImage($check['tmp_name']);

return $image->width() == $width ? true : false;
}

/**
* Check that the file has exact height requirement
*
* @param mixed $check Value to check
* @param int $height Height of Image
* @return bool Success
*/
public static function isThisHeight($check, $height)
{
if (!self::checkTmpFile($check))
{
return false;
}
$image = self::getImage($check['tmp_name']);

return $image->height() == $height ? false : true;
}

/**
* Check that the file has exact height requirement
*
* @param mixed $check Value to check
* @param int $height Height of Image
* @return bool Success
*/
public static function isThisWidthAndHeight($check, $width, $height)
{
if (!self::checkTmpFile($check))
{
return false;
}
$image = self::getImage($check['tmp_name']);

if($image->width() == $width and $image->height() == $height)
{
return true;
}else
{
return false;
}
}

/**
* Checks if the image has a correct aspect ratio
Expand Down

0 comments on commit fde0da8

Please sign in to comment.