- public function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false)
- {
- if ($keepRatio && $this->isGif($image)) {
- return $this->getPublicUrl($image->path);
- }
-
- $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/';
- $imagePath = $image->path;
- $thumbFilePath = dirname($imagePath) . $thumbDirName . basename($imagePath);
-
- if ($this->cache->has('images-' . $image->id . '-' . $thumbFilePath) && $this->cache->get('images-' . $thumbFilePath)) {
- return $this->getPublicUrl($thumbFilePath);
- }
-
- $storage = $this->getStorage($image->type);
- if ($storage->exists($thumbFilePath)) {
- return $this->getPublicUrl($thumbFilePath);
- }
-
- $thumbData = $this->resizeImage($storage->get($imagePath), $width, $height, $keepRatio);
-
- $storage->put($thumbFilePath, $thumbData);
- $storage->setVisibility($thumbFilePath, 'public');
- $this->cache->put('images-' . $image->id . '-' . $thumbFilePath, $thumbFilePath, 60 * 60 * 72);
-
-
- return $this->getPublicUrl($thumbFilePath);
- }
-
- /**
- * Resize image data.
- * @param string $imageData
- * @param int $width
- * @param int $height
- * @param bool $keepRatio
- * @return string
- * @throws ImageUploadException
- */
- protected function resizeImage(string $imageData, $width = 220, $height = null, bool $keepRatio = true)