larsvg/lvgimages

0.1.0 2020-08-31 12:45 UTC

This package is auto-updated.

Last update: 2024-10-14 19:25:21 UTC


README

Easily convert images to specific formats and sizes in your Laravel application.

This package uploads an image based on a Illuminate\Http\UploadedFile instance to your public folder. The images can be scaled and converted to WebP.

Here's an example of how the package can be used:

new WebPProcessor($image, 512, 256);
new WebPProcessor($image, 768, 384);
new WebPProcessor($image, 1024, 512);
new WebPProcessor($image, 1536, 1024);
new FallbackImageProcessor($image, 1536, 1024);

Installation

You can install the package through Composer.

composer require larsvg/lvgimages

Publish configuration to your project

php artisan vendor:publish --tag=lvgimages

Images are saved to the public/image directory. The fourth parameter can be optionally used to structurize the images in folders.

As a result you get nicely structurized responsive images, a use case could be the HTML picture tag.

<picture>
    <source srcset="{{ url('images/512x256.webp') }}" sizes="(max-width: 512px)" type="image/webp">
    <source srcset="{{ url('images/768x512.webp') }}" sizes="(min-width: 512px) and (max-width: 768px)" type="image/webp">
    <source srcset="{{ url('images/1024x512.webp') }}" sizes="(min-width: 768px) and (max-width: 1024px)" type="image/webp">
    <source srcset="{{ url('images/1536x1024.webp') }}" sizes="(min-width: 1024px)" type="image/webp">
    <source srcset="{{ url('images/1536x1024.jpg') }}" type="image/jpeg">
    <img src="{{ url('images/1536x1024.jpg') }}" alt="Responsive image">
</picture>