ebski/image-compressor

Compresses images to webp

1.0.0 2020-12-18 10:36 UTC

This package is auto-updated.

Last update: 2024-05-06 03:51:46 UTC


README

This library is handy if you need to compress an image to the format of webp. It uses cwebp to compress images into the webp format so make sure to have cwebp available on your server

Other compression formats can be added later if there is a need / want for it.

Installation

Using composer:

composer require ebski/image-compressor

to install cwebp on a linux machine

sudo apt-get update
sudo apt-get install webp

Usage

Instantiate the WebpCompressor class and call the function compressImage:

<?php

use Ebski\ImageCompressor\Compressors\WebpCompressor;
use Ebski\ImageCompressor\Quality;

public function example()
{
    $compressor = new WebpCompressor();
    $compressedImagePath = $compressor->compressImage('path_to_original_image', Quality::MEDIUM);
}

Supported image formats to compress from:

  • jpeg
  • png
  • webp
  • tiff

cleanup of compressed images happens automatically on destroy