Exemple #1
0
 /**
  * @param string $demand
  * @param bool|false $useWatermark
  * @return string
  * @throws Exception
  */
 public function getThumbnail($demand, $useWatermark = false)
 {
     $size = ThumbnailSize::getByDemand($demand);
     $thumb = Thumbnail::getImageThumbnailBySize($this, $size);
     /** @var string $src */
     $src = $thumb->file;
     if ($useWatermark === true) {
         $watermark = Watermark::findOne($size->default_watermark_id);
         if ($watermark !== null) {
             $water = ThumbnailWatermark::getThumbnailWatermark($thumb, $watermark);
             $src = $water->file;
         } else {
             throw new Exception(Yii::t('app', 'Set watermark id'));
         }
     }
     return $src;
 }
Exemple #2
0
 /**
  * @inheritdoc
  * @param bool $insert
  * @param array $changedAttributes
  * @throws BadRequestHttpException
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if (Yii::$app->getModule('image')->useWatermark == 1) {
         /** @var ThumbnailSize $size */
         $size = ThumbnailSize::findOne(ArrayHelper::getValue($this, 'size_id', 0));
         if ($size !== null) {
             $watermark = Watermark::findOne($size->default_watermark_id);
             if ($watermark !== null) {
                 ThumbnailWatermark::getThumbnailWatermark($this, $watermark);
             }
         } else {
             throw new BadRequestHttpException(Yii::t('app', 'Set thumbnail size'));
         }
     }
 }