Last active
July 4, 2016 12:50
-
-
Save valdiney/9c951b806d4f7d954238060b4517f174 to your computer and use it in GitHub Desktop.
This class is used to verify the image dimensions after upload.
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 | |
/** | |
[Image_dimensions] | |
This class is used to verify the image dimensions after upload. | |
@author Valdiney França | |
*/ | |
class Image_dimensions | |
{ | |
private $image; | |
private $needs_width; | |
private $needs_height; | |
private $very_large = "large"; | |
private $very_small = "small"; | |
# Receive the full path of the image | |
public function set_image($image_path) | |
{ | |
$this->image = getimagesize($image_path); | |
} | |
# Set the width values of the images that you wanna accept | |
public function set_width($width) | |
{ | |
$this->needs_width = $width; | |
} | |
# Set the height values of the images that you wanna accept | |
public function set_height($height) | |
{ | |
$this->needs_height = $height; | |
} | |
# Get the image width | |
public function get_width() | |
{ | |
return "{$this->image[0]}px"; | |
} | |
# Get the image height | |
public function get_height() | |
{ | |
return "{$this->image[1]}px"; | |
} | |
# [Private method] | |
# Checking the width dimensions | |
# @return : String : large or small | |
private function width_checking() | |
{ | |
if ($this->image[0] > $this->needs_width) { | |
return $this->very_large; | |
} | |
if ($this->image[0] < $this->needs_width) { | |
return $this->very_small; | |
} | |
return false; | |
} | |
# [Private method] | |
# Checking the height dimensions | |
# @return : String : large or small | |
private function height_checking() | |
{ | |
if ($this->image[1] > $this->needs_height) { | |
return $this->very_large; | |
} | |
if ($this->image[1] < $this->needs_height) { | |
return $this->very_small; | |
} | |
return false; | |
} | |
# [Public method] | |
# Checking the width dimensions | |
# @return : String : large or small | |
public function width_verify() | |
{ | |
if ($this->width_checking() == $this->very_large) { | |
return $this->very_large; | |
} | |
if ($this->width_checking() == $this->very_small) { | |
return $this->very_small; | |
} | |
return false; | |
} | |
# [Public method] | |
# Checking the height dimensions | |
# @return : String : large or small | |
public function height_verify() | |
{ | |
if ($this->height_checking() == $this->very_large) { | |
return $this->very_large; | |
} | |
if ($this->height_checking() == $this->very_small) { | |
return $this->very_small; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment