avanerk/statamic-image-to-webp

Converts uploaded images to WebP

1.2.0 2023-10-31 10:31 UTC

This package is auto-updated.

Last update: 2023-10-31 11:03:49 UTC


README

This addon automatically converts uploaded images to WebP format, providing smaller file sizes, faster load times, and reduced server bandwidth. It's a simple yet effective solution for developers aiming to improve website performance and SEO without the hassle of manual image optimization.

Installation

You can install the addon via Composer:

composer require avanerk/statamic-image-to-webp

Configuration

After installation, you can publish the configuration file with:

php artisan vendor:publish --tag="image-to-webp-config"

This will create a image-to-webp.php file in your config folder. Here you can specify the file extensions that you would like to convert, whether to remove the original image, and the target queue for the convert image job.

File Extensions

By default, all file extensions will be converted to WebP. If you only want to convert specific file types, you can specify them in a comma-separated list. For example:

'extensions' => 'png, jpeg',

Remove Original Image

By default, the original image will be removed. If you would like to keep the original image, you can set this flag to false.

'remove_original' => false,

Queue

If you use a queue driver other than 'sync' for the convert image job, be aware that the process may take a few seconds, and you might not see the webp image immediately. For some, this delay is not a concern and can be resolved simply by refreshing the browser. However, if you prefer to have the webp image available immediately, set the queue driver for this job to 'sync', which will process the convert job synchronously. Additionally, you have the option to specify the name of the target queue; if not specified, the job will default to the default queue.

'queue' => 'your-queue-name',

Usage

Once configured, the addon will automatically convert uploaded images to WebP format according to your configuration.

Requirements

The GD extension must be installed and compiled with WebP support.

License

This addon is open-sourced software licensed under the MIT license.