eihror / compress-image

无损压缩图片

v0.0.6 2018-08-03 19:30 UTC

README

Latest Stable Version Total Downloads Latest Unstable Version License

压缩图片

无损压缩图片

如何使用

将此项目克隆到您想要使用的项目中

composer require eihror/compress-image

创建变量以接收元素

$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.

该质量仅适用于JPG图片。但如果您想将文件转换为PNG,您必须手动通过代码进行更改。GIF不会影响质量

PNG默认质量:9(0 - 无压缩,9 - 最大压缩) 创建类的新实例

$image_compress = new Eihror\Compress\Compress($file, $new_name_image, $quality, $pngQuality, $destination, $maxsize);

然后通过调用函数 compress_image 进行压缩

$image_compress->compress_image();

该函数将仅返回带有相应扩展名的新压缩图片名称

就这样!如有不同或错误之处,请随意使用并改进代码