项目作者: tihiy-production

项目描述 :
PHP library for image compression without loss of quality for PNG and JPEG formats
高级语言: PHP
项目地址: git://github.com/tihiy-production/php-image-compressor.git
创建时间: 2021-02-03T14:25:57Z
项目社区:https://github.com/tihiy-production/php-image-compressor

开源协议:MIT License

下载


Compress images

Latest Version on Packagist
Total Downloads
Software License

ImageCompressor - this is an easy way to compress images on the fly.

Requirements

The following libraries need to be installed:

Jpegoptim & Pngquant

  1. sudo apt-get -y install jpegoptim pngquant

Installation

Execute the following command to install this package as a dependency in your project:

  1. composer require "tihiy-production/php-image-compressor"

Usage

You can choose a local file as the source and write it to another file.

  1. $source = tihiy\Compressor\ImageCompressor::sourceFile('uncompressed.jpg');
  2. $source->toFile('compressed.jpg');

You can upload an image content as the source and get the compressed image data.

  1. $sourceData = file_get_contents('uncompressed.jpg');
  2. $resultData = tihiy\Compressor\ImageCompressor::sourceContent($sourceData)->toContent();

You can specify URL as a source to the image and compress it without having to upload.

  1. $source = tihiy\Compressor\ImageCompressor::sourceUrl('https://example.com/uncompressed.jpg');
  2. $source->toFile('compressed.jpg');

License

This software is licensed under the MIT License. View the license.