temporary image handling and some responsive
This commit is contained in:
1 parent
0ae5f49bcf
commit
50ec0eebf2
27 files changed
+107
-48
No files matched your search
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Catalog;
|
||||
|
||||
use Lunar\Base\StandardMediaDefinitions;
|
||||
use Spatie\Image\Enums\Constraint;
|
||||
use Spatie\MediaLibrary\HasMedia;
|
||||
use Spatie\MediaLibrary\MediaCollections\MediaCollection;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
|
||||
/**
|
||||
* INTERIM — belongs in boboko-core (see the core task in the image
|
||||
* performance discussion). Delete this class and point
|
||||
* config/lunar/media.php back at core's definitions once it lands there.
|
||||
*
|
||||
* Storefront product image sizes for srcset: WebP at fixed widths, the
|
||||
* original's aspect ratio preserved and never upscaled. Replaces Lunar's
|
||||
* square white-padded zoom/large/medium conversions (nothing reads them);
|
||||
* the parent's `small` conversion stays for the admin panel.
|
||||
*/
|
||||
class ProductMediaDefinitions extends StandardMediaDefinitions
|
||||
{
|
||||
/** Conversion name => width in px. Named `w{width}` so the srcset can be built from the name. */
|
||||
public const WIDTHS = [
|
||||
'w160' => 160,
|
||||
'w400' => 400,
|
||||
'w800' => 800,
|
||||
'w1200' => 1200,
|
||||
'w1600' => 1600,
|
||||
];
|
||||
|
||||
protected function registerCollectionConversions(MediaCollection $collection, HasMedia $model): void
|
||||
{
|
||||
$collection->registerMediaConversions(function (Media $media) use ($model) {
|
||||
foreach (self::WIDTHS as $name => $width) {
|
||||
$model->addMediaConversion($name)
|
||||
->width($width, [Constraint::PreserveAspectRatio, Constraint::DoNotUpsize])
|
||||
->format('webp')
|
||||
->quality(80);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user