You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

11 years ago
  1. <?php
  2. abstract class Image extends File
  3. {
  4. public $width;
  5. public $height;
  6. public $type;
  7. public $size;
  8. public $original_filename;
  9. /**
  10. * @var ImageVariant[]
  11. */
  12. public $variants = array();
  13. protected static $max_width;
  14. protected static $max_height;
  15. protected static $sizes = array();
  16. protected static $watermarks = array();
  17. public static function getClassName()
  18. {
  19. return get_called_class();
  20. }
  21. /**
  22. * @param $class string|StdClass
  23. * @throws ErrorException
  24. */
  25. public static function checkSubClass($class)
  26. {
  27. if (!self::getIsSubClass($class)) {
  28. throw new ErrorException('Class "' . $class . '" mast be extend of "Image".');
  29. }
  30. }
  31. /**
  32. * @param $class string|StdClass
  33. * @return bool
  34. */
  35. public static function getIsSubClass($class)
  36. {
  37. return (get_parent_class($class) == __CLASS__);
  38. }
  39. public static function getSizes()
  40. {
  41. return static::$sizes;
  42. }
  43. public static function getWatermark($size)
  44. {
  45. return (isset(static::$watermarks[$size])) ? static::$watermarks[$size] : false;
  46. }
  47. public static function getMaxWidth()
  48. {
  49. return static::$max_width;
  50. }
  51. public static function getMaxHeight()
  52. {
  53. return static::$max_height;
  54. }
  55. /**
  56. * @param $size
  57. * @param $force_create
  58. * @return ImageVariant
  59. */
  60. public function getVariant($size, $force_create = false)
  61. {
  62. return parent::getImageVariant($size, $force_create);
  63. }
  64. }