Skip to content

Instantly share code, notes, and snippets.

@valdiney
Created July 4, 2016 13:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/958a5fd813e5883d38468ff280df9f15 to your computer and use it in GitHub Desktop.
Save valdiney/958a5fd813e5883d38468ff280df9f15 to your computer and use it in GitHub Desktop.
<?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