Exemple #1
0
 /**
  * Return thumb of image by size or create if not exist
  * @param $image Image
  * @param $size ThumbnailSize
  * @return Thumbnail
  */
 public static function getImageThumbnailBySize($image, $size)
 {
     $thumb = static::findOne(['img_id' => $image->id, 'size_id' => $size->id]);
     if ($thumb === null) {
         $thumb = new Thumbnail();
         $thumb->setAttributes(['img_id' => $image->id, 'size_id' => $size->id]);
         $thumb->thumb_path = static::createThumbnail($image, $size);
         $thumb->save();
     }
     return $thumb;
 }
Exemple #2
0
 /**
  * Return thumb of image by size or create if not exist
  * @param $image Image
  * @param $size ThumbnailSize
  * @return Thumbnail
  */
 public static function getImageThumbnailBySize($image, $size)
 {
     $cacheKey = 'thumbBySize:' . $image->id . ';' . $size->id;
     $thumb = Yii::$app->cache->get($cacheKey);
     if ($thumb === false) {
         $thumb = static::findOne(['img_id' => $image->id, 'size_id' => $size->id]);
         if ($thumb === null) {
             $thumb = new Thumbnail();
             $thumb->setAttributes(['img_id' => $image->id, 'size_id' => $size->id]);
             $thumb->thumb_path = static::createThumbnail($image, $size);
             $thumb->save();
         }
         Yii::$app->cache->set($cacheKey, $thumb, 86400);
     }
     return $thumb;
 }