Gallery.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace manager\models;
  3. use app\forks\galleryManager\GalleryBehavior;
  4. use Yii;
  5. /**
  6. * @property string $inject
  7. */
  8. class Gallery extends \app\models\base\Gallery
  9. {
  10. public function behaviors()
  11. {
  12. return [
  13. 'galleryBehavior' => [
  14. 'class' => GalleryBehavior::className(),
  15. 'type' => 'post_gallery',
  16. 'extension' => 'png',
  17. 'directory' => Yii::getAlias('@webroot') . '/images/post_gallery/gallery',
  18. 'url' => Yii::getAlias('@web') . '/images/post_gallery/gallery',
  19. 'versions' => [
  20. 'small' => function ($img) {
  21. /** @var \Imagine\Image\ImageInterface $img */
  22. return $img
  23. ->copy()
  24. ->thumbnail(new \Imagine\Image\Box(200, 200));
  25. },
  26. 'medium' => function ($img) {
  27. /** @var \Imagine\Image\ImageInterface $img */
  28. $dstSize = $img->getSize();
  29. $maxWidth = 800;
  30. if ($dstSize->getWidth() > $maxWidth) {
  31. $dstSize = $dstSize->widen($maxWidth);
  32. }
  33. return $img
  34. ->copy()
  35. ->resize($dstSize);
  36. },
  37. 'large' => function ($img) {
  38. /** @var \Imagine\Image\ImageInterface $img */
  39. $dstSize = $img->getSize();
  40. $maxWidth = 1920;
  41. if ($dstSize->getWidth() > $maxWidth) {
  42. $dstSize = $dstSize->widen($maxWidth);
  43. }
  44. return $img
  45. ->copy()
  46. ->resize($dstSize);
  47. },
  48. ]
  49. ]
  50. ];
  51. }
  52. public function getInject()
  53. {
  54. return "##_gallery-".$this->id."##";
  55. }
  56. }