eihror / compress-image
Compress your image without losing quality
Installs: 5 026
Dependents: 2
Suggesters: 0
Security: 0
Stars: 33
Watchers: 5
Forks: 19
Open Issues: 3
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-11-11 00:07:55 UTC
README
Compress Image
Compress your image without losing quality
How to use
Clone this project inside the project that you want to use
composer require eihror/compress-image
Create variables to receive the elements
$file = 'koala.jpg'; //file that you wanna compress
$new_name_image = 'koala_mini'; //name of new file compressed
$quality = 60; // Value that I chose
$pngQuality = 9; // Exclusive for PNG files
$destination = 'content'; //This destination must be exist on your project
$maxsize = 5245330; //Set maximum image size in bytes. if no value given 5mb by default.
The quality works only for JPG�s images. But if you want to change the file to PNG�s, you have to change manually via code. GIF doesn't affect the quality
Default quality for PNG: 9 ( 0 - no compression, 9 - max compression ) Create a new instance of a class
$image_compress = new Eihror\Compress\Compress($file, $new_name_image, $quality, $pngQuality, $destination, $maxsize);
And make the compression calling the function compress_image
$image_compress->compress_image();
This function will return only the name of new image compressed with your respective extension
That´s it! Feel free to use and making the code better if you find something different or wrong