Extend Image class. Separate to ImageVariant. Remove _is_new_record.

This commit is contained in:
Alexander Demidov
2013-05-27 12:49:32 +04:00
parent 47d0c54ef1
commit 4ace9e1b02
5 changed files with 97 additions and 77 deletions

View File

@ -2,26 +2,41 @@
abstract class UploadHelper
{
/**
* @param $proportion
* @param $file_path
* @return bool
* @throws ErrorException
*/
public static function imageCompareAspectRatio($proportion, $file_path)
{
if (file_exists($file_path) && is_readable($file_path) && is_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;
}
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;
}
}
return false;
}
/**
* @param $size
* @param $file_path
* @return bool
* @throws ErrorException
*/
public static function imageCompareSize($size, $file_path)
{
if (file_exists($file_path) && is_readable($file_path) && is_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;
}
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;
}
}
return false;