tihiy-production / php-image-compressor
ImageCompressor - this is an easy way to compress images on the fly
Installs: 2 072
Dependents: 0
Suggesters: 0
Security: 0
Stars: 21
Watchers: 1
Forks: 2
Open Issues: 0
Requires
- php: >=7.0.0
- ext-fileinfo: *
Requires (Dev)
- phpunit/phpunit: ^6
README
ImageCompressor - this is an easy way to compress images on the fly.
Requirements
The following libraries need to be installed:
Jpegoptim & Pngquant
sudo apt-get -y install jpegoptim pngquant
Installation
Execute the following command to install this package as a dependency in your project:
composer require "tihiy-production/php-image-compressor"
Usage
You can choose a local file as the source and write it to another file.
$source = tihiy\Compressor\ImageCompressor::sourceFile('uncompressed.jpg'); $source->toFile('compressed.jpg');
You can upload an image content as the source and get the compressed image data.
$sourceData = file_get_contents('uncompressed.jpg'); $resultData = tihiy\Compressor\ImageCompressor::sourceContent($sourceData)->toContent();
You can specify URL as a source to the image and compress it without having to upload.
$source = tihiy\Compressor\ImageCompressor::sourceUrl('https://example.com/uncompressed.jpg'); $source->toFile('compressed.jpg');
License
This software is licensed under the MIT License. View the license.