- * @param int $width
- * @param int $height
- * @param bool $keepRatio
- * @return string
- */
- private function getThumbnail(Image $image, $width = 220, $height = 220, $keepRatio = false)
- {
- $thumbDirName = '/' . ($keepRatio ? 'scaled-' : 'thumbs-') . $width . '-' . $height . '/';
- $thumbFilePath = dirname($image->path) . $thumbDirName . basename($image->path);
-
- if ($this->cache->has('images-' . $image->id . '-' . $thumbFilePath) && $this->cache->get('images-' . $thumbFilePath)) {
- return $this->getPublicUrl($thumbFilePath);
- }
-
- $storage = $this->getStorage();
-
- if ($storage->exists($thumbFilePath)) {
- return $this->getPublicUrl($thumbFilePath);
- }
-
- // Otherwise create the thumbnail
- $thumb = $this->imageTool->make($storage->get($image->path));
- if ($keepRatio) {
- $thumb->resize($width, null, function ($constraint) {
- $constraint->aspectRatio();
- $constraint->upsize();
- });
- } else {
- $thumb->fit($width, $height);
- }
-
- $thumbData = (string)$thumb->encode();
- $storage->put($thumbFilePath, $thumbData);
- $this->cache->put('images-' . $image->id . '-' . $thumbFilePath, $thumbFilePath, 60 * 72);
-
- return $this->getPublicUrl($thumbFilePath);
- }
-
- /**
- * Gets a public facing url for an image by checking relevant environment variables.
- * @param $filePath