Files
image/Image.php

93 lines
2.0 KiB
PHP
Raw Normal View History

2013-05-24 13:27:47 +04:00
<?php
2014-06-02 20:30:44 +04:00
namespace dimti\Image;
2013-05-24 13:27:47 +04:00
abstract class Image extends File
2013-05-24 13:27:47 +04:00
{
public $width;
public $height;
public $type;
public $size;
2013-05-24 13:27:47 +04:00
public $original_filename;
2013-11-25 13:04:46 +04:00
/**
* @var ImageVariant[]
*/
2013-05-24 13:27:47 +04:00
public $variants = array();
protected static $max_width;
protected static $max_height;
protected static $sizes = array();
2013-05-24 13:27:47 +04:00
protected static $watermarks = array();
public static function getClassName()
{
return get_called_class();
}
2013-05-24 13:27:47 +04:00
/**
2014-06-02 21:03:50 +04:00
* @param $class string|\StdClass
* @throws \ErrorException
2013-05-24 13:27:47 +04:00
*/
public static function checkSubClass($class)
2013-05-24 13:27:47 +04:00
{
if (!self::getIsSubClass($class)) {
2014-06-02 21:03:50 +04:00
throw new \ErrorException('Class "' . $class . '" mast be extend of "Image".');
2013-05-24 13:27:47 +04:00
}
}
/**
2014-06-02 21:03:50 +04:00
* @param $class string|\StdClass
* @return bool
*/
public static function getIsSubClass($class)
{
$parent_class = get_parent_class($class);
if ($parent_class == __CLASS__) {
return true;
}
if (get_parent_class($parent_class)) {
return self::getIsSubClass($parent_class);
}
return false;
}
public static function getSizes()
{
return static::$sizes;
2013-05-24 13:27:47 +04:00
}
public static function getWatermark($size)
{
return (isset(static::$watermarks[$size])) ? static::$watermarks[$size] : false;
}
public static function getMaxWidth()
{
return static::$max_width;
}
public static function getMaxHeight()
{
return static::$max_height;
}
/**
* @param $size
* @param bool $force_create
* @param bool $important_create
*
* @return ImageVariant
*/
public function getVariant($size, $force_create = false, $important_create = false)
{
if ($force_create && !$important_create && array_key_exists($size, $this->variants) && $this->variants[$size]['size'] === null) {
$important_create = true;
}
return parent::getImageVariant($size, $force_create, $important_create);
}
2013-05-24 13:27:47 +04:00
}