Skip to content

Commit

Permalink
Image optimization (#4)
Browse files Browse the repository at this point in the history
* Optimize images
* Add fallback for swf files
  • Loading branch information
lisa-fehr authored Jun 7, 2023
1 parent 539f7b3 commit 72c8d2b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/Console/Commands/GenerateImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,24 @@ private function resizeImage($originalImage)

if ($gallery) {
$thumbPath = $this->thumbnailDestination . '/' . $gallery->thumb;
$imagePath = $this->imageDestination . '/' . $gallery->img . '.' . $gallery->type;

$imagePath = $this->imageDestination . '/' . $gallery->img;
if ($gallery->type === 'swf') {
$imagePath .= ".jpg";
} else {
$imagePath .= "." . $gallery->type;
}

if (file_exists($imagePath)) {
$this->info('Image and thumbnail already created: ' . $originalImage);
return;
}

Image::make($originalPath)
->resize(self::THUMBNAIL_WIDTH, self::THUMBNAIL_HEIGHT)
->sharpen(5)
->save($thumbPath, self::THUMBNAIL_QUALITY, pathinfo($gallery->thumb, PATHINFO_EXTENSION));
->limitColors(25, '#ff9900')
->save($thumbPath, self::THUMBNAIL_QUALITY);

$image = Image::make($originalPath);
[$width, $height] = $this->calculateWidthHeight($image);
Expand All @@ -91,8 +103,10 @@ private function resizeImage($originalImage)
})->save($imagePath);

$this->info('Created an image and thumbnail: ' . $originalImage);
} elseif ($name) {
$this->info('Could not find img:' . $name);
} else {
$this->info('Could not find: ' . $originalImage);
$this->info('Could not find original img:' . $originalImage);
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/Models/UberGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function getImageAttribute() : string
if (Storage::disk('gallery')->exists($url)) {
return Storage::disk('gallery')->temporaryUrl($url, Carbon::now()->addDay());
}
$fallbackForSwf = $this->tag->directory . '/' . $this->img . '.jpg';
if (Storage::disk('gallery')->exists($fallbackForSwf)) {
return Storage::disk('gallery')->temporaryUrl($fallbackForSwf, Carbon::now()->addDay());
}
return Storage::disk('gallery')->url('/missing-image.gif');
}

Expand Down

0 comments on commit 72c8d2b

Please sign in to comment.