-
- // 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
- * @return string
- */
- private function getPublicUrl($filePath)
- {
- if ($this->storageUrl === null) {
- $storageUrl = env('STORAGE_URL');
-
- // Get the standard public s3 url if s3 is set as storage type
- if ($storageUrl == false && env('STORAGE_TYPE') === 's3') {
- $storageDetails = config('filesystems.disks.s3');
- $storageUrl = 'https://s3-' . $storageDetails['region'] . '.amazonaws.com/' . $storageDetails['bucket'];
- }
-
- $this->storageUrl = $storageUrl;
- }
-
- return ($this->storageUrl == false ? '' : rtrim($this->storageUrl, '/')) . $filePath;
- }
-
-
- /**
- * Get the storage that will be used for storing images.
- * @return FileSystemInstance
- */
- private function getStorage()
- {
- if ($this->storageInstance !== null) return $this->storageInstance;
-
- $storageType = env('STORAGE_TYPE');
- $this->storageInstance = $this->fileSystem->disk($storageType);
-
- return $this->storageInstance;