ImageManagerStatic.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Intervention\Image;
  3. use Closure;
  4. class ImageManagerStatic
  5. {
  6. /**
  7. * Instance of Intervention\Image\ImageManager
  8. *
  9. * @var ImageManager
  10. */
  11. public static $manager;
  12. /**
  13. * Creates a new instance
  14. *
  15. * @param ImageManager $manager
  16. */
  17. public function __construct(ImageManager $manager = null)
  18. {
  19. self::$manager = $manager ? $manager : new ImageManager;
  20. }
  21. /**
  22. * Get or create new ImageManager instance
  23. *
  24. * @return ImageManager
  25. */
  26. public static function getManager()
  27. {
  28. return self::$manager ? self::$manager : new ImageManager;
  29. }
  30. /**
  31. * Statically create new custom configured image manager
  32. *
  33. * @param array $config
  34. *
  35. * @return ImageManager
  36. */
  37. public static function configure(array $config = [])
  38. {
  39. return self::$manager = self::getManager()->configure($config);
  40. }
  41. /**
  42. * Statically initiates an Image instance from different input types
  43. *
  44. * @param mixed $data
  45. *
  46. * @return \Intervention\Image\Image
  47. * @throws \Intervention\Image\Exception\NotReadableException
  48. */
  49. public static function make($data)
  50. {
  51. return self::getManager()->make($data);
  52. }
  53. /**
  54. * Statically creates an empty image canvas
  55. *
  56. * @param int $width
  57. * @param int $height
  58. * @param mixed $background
  59. *
  60. * @return \Intervention\Image\Image
  61. */
  62. public static function canvas($width, $height, $background = null)
  63. {
  64. return self::getManager()->canvas($width, $height, $background);
  65. }
  66. /**
  67. * Create new cached image and run callback statically
  68. *
  69. * @param Closure $callback
  70. * @param int $lifetime
  71. * @param boolean $returnObj
  72. *
  73. * @return mixed
  74. */
  75. public static function cache(Closure $callback, $lifetime = null, $returnObj = false)
  76. {
  77. return self::getManager()->cache($callback, $lifetime, $returnObj);
  78. }
  79. }