Files
image/UploadHelper.class.php

60 lines
1.7 KiB
PHP
Raw Normal View History

2013-05-24 13:27:47 +04:00
<?php
abstract class UploadHelper
{
/**
* @param $proportion
* @param $file_path
* @return bool
* @throws ErrorException
*/
2013-05-24 13:27:47 +04:00
public static function imageCompareAspectRatio($proportion, $file_path)
{
if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) {
throw new ErrorException('Unable to read file "' . $file_path . '".');
}
if ($imagesize = getimagesize($file_path)) {
$proprtion_parts = explode('x', $proportion);
if ($proprtion_parts[0] / $proprtion_parts[1] === $imagesize[0] / $imagesize[1]) {
return true;
}
2013-05-24 13:27:47 +04:00
}
return false;
2013-05-24 13:27:47 +04:00
}
/**
* @param $size
* @param $file_path
* @return bool
* @throws ErrorException
*/
public static function imageCompareSize($size, $file_path)
2013-05-24 13:27:47 +04:00
{
if (!(file_exists($file_path) && is_readable($file_path) && is_file($file_path))) {
throw new ErrorException('Unable to read file "' . $file_path . '".');
}
if ($imagesize = getimagesize($file_path)) {
$size_parts = explode('x', $size);
if ($imagesize[0] == $size_parts[0] && $imagesize[1] == $size_parts[1]) {
return true;
}
2013-05-24 13:27:47 +04:00
}
return false;
2013-05-24 13:27:47 +04:00
}
/**
* @param $size
* @param $file_path
* @return bool
*/
public static function imageCheckMinSize($size, $file_path)
{
$imagesize = getimagesize($file_path);
$size_parts = explode('x', $size);
if ($imagesize[0] >= $size_parts[0] && $imagesize[1] >= $size_parts[1]) {
return true;
} else {
return false;
}
}
2013-05-24 13:27:47 +04:00
}