Skip to content

Instantly share code, notes, and snippets.

@valdiney
Last active July 4, 2016 12:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valdiney/9c951b806d4f7d954238060b4517f174 to your computer and use it in GitHub Desktop.
Save valdiney/9c951b806d4f7d954238060b4517f174 to your computer and use it in GitHub Desktop.
This class is used to verify the image dimensions after upload.
<?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