WIP
This commit is contained in:
@@ -37,9 +37,33 @@ class ImageController extends Controller
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(Image $image) : BinaryFileResponse
|
||||
public function show(Image $image, string $size = 'original') : BinaryFileResponse
|
||||
{
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/thumbnail/' . $image->id . '.avif'));
|
||||
return response()->file(Storage::disk('images')->path($image->album->id . '/' . $size . '/' . $image->id . '.avif'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the thumbnail of the specified resource.
|
||||
*/
|
||||
public function thumbnail(Image $image) : BinaryFileResponse
|
||||
{
|
||||
return $this->show($image, 'thumbnail');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the lightbox of the specified resource.
|
||||
*/
|
||||
public function lightbox(Image $image) : BinaryFileResponse
|
||||
{
|
||||
return $this->show($image, 'lightbox');
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the lightbox of the specified resource.
|
||||
*/
|
||||
public function download(Image $image)
|
||||
{
|
||||
return Storage::disk('images')->download($image->album_id . '/original/' . $image->id . '.avif', name: $image->album->name . '_' . $image->id . '.avif');
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,16 +33,11 @@ class GenerateFullscreen implements ShouldQueue
|
||||
return;
|
||||
}
|
||||
|
||||
$image = InterventionImage::read($this->source);
|
||||
if($image->width() >= $image->height()) {
|
||||
// landscape
|
||||
$image->scaleDown(width: config('gallery.image.fullscreen.maxWidth', 2000));
|
||||
} else {
|
||||
// portrait
|
||||
$image->scaleDown(height: config('gallery.image.fullscreen.maxHeight', 2000));
|
||||
}
|
||||
$lightbox = InterventionImage::read($this->source);
|
||||
$lightbox = $lightbox->scaleDown(height: config('gallery.image.fullscreen.height', 2000));
|
||||
|
||||
Storage::disk('images')->put($this->destination, $image->toAvif(config('gallery.image.quality', 80)));
|
||||
Storage::disk('images')->put($this->destination, $lightbox->toAvif(config('gallery.image.quality', 80)));
|
||||
$this->image->setLightboxSize($lightbox->width(), $lightbox->height());
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
|
||||
@@ -33,16 +33,10 @@ class GenerateThumbnail implements ShouldQueue
|
||||
return;
|
||||
}
|
||||
|
||||
$image = InterventionImage::read($this->source);
|
||||
if($image->width() >= $image->height()) {
|
||||
// landscape
|
||||
$image->scaleDown(width: config('gallery.image.thumbnail.maxWidth', 150));
|
||||
} else {
|
||||
// portrait
|
||||
$image->scaleDown(height: config('gallery.image.thumbnail.maxHeight', 150));
|
||||
}
|
||||
$thumbnail = InterventionImage::read($this->source);
|
||||
$thumbnail = $thumbnail->scaleDown(height: config('gallery.image.thumbnail.height', 640), width: config('gallery.image.thumbnail.width', 640));
|
||||
|
||||
Storage::disk('images')->put($this->destination, $image->toAvif(config('gallery.image.quality', 80)));
|
||||
Storage::disk('images')->put($this->destination, $thumbnail->toAvif(config('gallery.image.quality', 80)));
|
||||
}
|
||||
|
||||
public function failed(?Throwable $exception): void
|
||||
|
||||
@@ -18,6 +18,8 @@ class Image extends Model implements HasThumbnail
|
||||
*/
|
||||
protected $attributes = [
|
||||
'isCover' => false,
|
||||
'lightboxWidth' => 0,
|
||||
'lightboxHeight' => 0,
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -25,7 +27,7 @@ class Image extends Model implements HasThumbnail
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = ['album_id'];
|
||||
protected $fillable = ['album_id', 'lightboxWidth', 'lightboxHeight'];
|
||||
|
||||
public function album(): BelongsTo
|
||||
{
|
||||
@@ -33,6 +35,24 @@ class Image extends Model implements HasThumbnail
|
||||
}
|
||||
|
||||
public function getThumbnail() : string {
|
||||
return route('image.show', $this);
|
||||
return route('image.thumbnail', $this);
|
||||
}
|
||||
|
||||
public function getDownload() : string {
|
||||
return route('image.download', $this);
|
||||
}
|
||||
|
||||
public function setLightboxSize(int $width, int $height) : void {
|
||||
$this->lightboxWidth = $width;
|
||||
$this->lightboxHeight = $height;
|
||||
$this->save();
|
||||
}
|
||||
|
||||
public function getLightboxAttribute() : array {
|
||||
return [
|
||||
'location' => route('image.lightbox', $this),
|
||||
'width' => $this->lightboxWidth,
|
||||
'height' => $this->lightboxHeight,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user