Created
July 4, 2016 13:39
-
-
Save valdiney/958a5fd813e5883d38468ff280df9f15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
[ImageDimensionValidation] | |
This class is used to verify the image dimensions after upload. | |
@author Valdiney França | |
*/ | |
class ImageDimensionValidation | |
{ | |
private $image; | |
private $maxWidth; | |
private $minWidth; | |
# Receive the full path of the image | |
public function setImage($imagePath) | |
{ | |
$this->image = getimagesize($imagePath); | |
} | |
public function setMinWidth($minWidth) | |
{ | |
$this->minWidth = $minWidth; | |
} | |
public function setMaxWidth($maxWidth) | |
{ | |
$this->maxWidth = $maxWidth; | |
} | |
public function setMinHeight($minHeight) | |
{ | |
$this->minHeight = $minHeight; | |
} | |
public function setMaxHeight($maxHeight) | |
{ | |
$this->maxHeight = $maxHeight; | |
} | |
public function checkMinMaxWidth() | |
{ | |
if ($this->image[0] > $this->maxWidth AND $this->image[0] < $this->minWidth) { | |
return true; | |
} | |
return false; | |
} | |
public function checkMinMaxHeight() | |
{ | |
if ($this->image[1] > $this->maxHeight AND $this->image[1] < $this->minHeight) { | |
return true; | |
} | |
return false; | |
} | |
public function checkMaxWidth() | |
{ | |
if ($this->image[0] > $this->maxWidth OR $this->image[0] < $this->minWidth) { | |
return true; | |
} | |
return false; | |
} | |
public function checkMaxHeight() | |
{ | |
if ($this->image[1] > $this->maxHeight OR $this->image[1] < $this->minWidth) { | |
return true; | |
} | |
return false; | |
} | |
public function checkWidthAndHeight() | |
{ | |
if ($this->checkMaxWidth() OR checkMaxHeight()) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment