Subiendo proyecto completo sin restricciones de git ignore
This commit is contained in:
55
vendor/spatie/image-optimizer/.github/CONTRIBUTING.md
vendored
Normal file
55
vendor/spatie/image-optimizer/.github/CONTRIBUTING.md
vendored
Normal file
@@ -0,0 +1,55 @@
|
||||
# Contributing
|
||||
|
||||
Contributions are **welcome** and will be fully **credited**.
|
||||
|
||||
Please read and understand the contribution guide before creating an issue or pull request.
|
||||
|
||||
## Etiquette
|
||||
|
||||
This project is open source, and as such, the maintainers give their free time to build and maintain the source code
|
||||
held within. They make the code freely available in the hope that it will be of use to other developers. It would be
|
||||
extremely unfair for them to suffer abuse or anger for their hard work.
|
||||
|
||||
Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the
|
||||
world that developers are civilized and selfless people.
|
||||
|
||||
It's the duty of the maintainer to ensure that all submissions to the project are of sufficient
|
||||
quality to benefit the project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do not be upset or abusive if your submission is not used.
|
||||
|
||||
## Viability
|
||||
|
||||
When requesting or submitting new features, first consider whether it might be useful to others. Open
|
||||
source projects are used by many developers, who may have entirely different needs to your own. Think about
|
||||
whether or not your feature is likely to be used by other users of the project.
|
||||
|
||||
## Procedure
|
||||
|
||||
Before filing an issue:
|
||||
|
||||
- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident.
|
||||
- Check to make sure your feature suggestion isn't already present within the project.
|
||||
- Check the pull requests tab to ensure that the bug doesn't have a fix in progress.
|
||||
- Check the pull requests tab to ensure that the feature isn't already in progress.
|
||||
|
||||
Before submitting a pull request:
|
||||
|
||||
- Check the codebase to ensure that your feature doesn't already exist.
|
||||
- Check the pull requests to ensure that another person hasn't already submitted the feature or fix.
|
||||
|
||||
## Requirements
|
||||
|
||||
If the project maintainer has any additional requirements, you will find them listed here.
|
||||
|
||||
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).
|
||||
|
||||
- **Add tests!** - Your patch won't be accepted if it doesn't have tests.
|
||||
|
||||
- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.
|
||||
|
||||
- **Consider our release cycle** - We try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.
|
||||
|
||||
- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.
|
||||
|
||||
- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.
|
||||
|
||||
**Happy coding**!
|
||||
21
vendor/spatie/image-optimizer/.github/LICENSE.md
vendored
Normal file
21
vendor/spatie/image-optimizer/.github/LICENSE.md
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
# The MIT License (MIT)
|
||||
|
||||
Copyright (c) Spatie bvba <info@spatie.be>
|
||||
|
||||
> Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
> of this software and associated documentation files (the "Software"), to deal
|
||||
> in the Software without restriction, including without limitation the rights
|
||||
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
> copies of the Software, and to permit persons to whom the Software is
|
||||
> furnished to do so, subject to the following conditions:
|
||||
>
|
||||
> The above copyright notice and this permission notice shall be included in
|
||||
> all copies or substantial portions of the Software.
|
||||
>
|
||||
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
> THE SOFTWARE.
|
||||
23
vendor/spatie/image-optimizer/.github/workflows/php-cs-fixer.yml
vendored
Normal file
23
vendor/spatie/image-optimizer/.github/workflows/php-cs-fixer.yml
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
name: Check & fix styling
|
||||
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.head_ref }}
|
||||
|
||||
- name: Run PHP CS Fixer
|
||||
uses: docker://oskarstark/php-cs-fixer-ga
|
||||
with:
|
||||
args: --config=.php_cs.dist --allow-risky=yes
|
||||
|
||||
- name: Commit changes
|
||||
uses: stefanzweifel/git-auto-commit-action@v4
|
||||
with:
|
||||
commit_message: Fix styling
|
||||
45
vendor/spatie/image-optimizer/.github/workflows/tests.yml
vendored
Normal file
45
vendor/spatie/image-optimizer/.github/workflows/tests.yml
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
name: Tests
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ${{ matrix.os }}
|
||||
strategy:
|
||||
fail-fast: true
|
||||
matrix:
|
||||
os: [ubuntu-latest]
|
||||
php: [8.0, 7.4, 7.3, 7.2]
|
||||
dependency-version: [prefer-lowest, prefer-stable]
|
||||
|
||||
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
|
||||
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install optimizers
|
||||
run: |
|
||||
sudo apt-get update -y
|
||||
sudo apt-get install -y jpegoptim pngquant gifsicle optipng libjpeg-progs webp
|
||||
sudo npm install -g svgo
|
||||
|
||||
- name: Setup PHP
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ matrix.php }}
|
||||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
|
||||
coverage: none
|
||||
|
||||
- name: Setup Problem Matches
|
||||
run: |
|
||||
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
|
||||
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
|
||||
|
||||
- name: Execute tests
|
||||
run: vendor/bin/phpunit
|
||||
|
||||
40
vendor/spatie/image-optimizer/.php_cs.dist
vendored
Normal file
40
vendor/spatie/image-optimizer/.php_cs.dist
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
$finder = Symfony\Component\Finder\Finder::create()
|
||||
->in([
|
||||
__DIR__ . '/src',
|
||||
__DIR__ . '/tests',
|
||||
])
|
||||
->name('*.php')
|
||||
->notName('*.blade.php')
|
||||
->ignoreDotFiles(true)
|
||||
->ignoreVCS(true);
|
||||
|
||||
return PhpCsFixer\Config::create()
|
||||
->setRules([
|
||||
'@PSR2' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
|
||||
'no_unused_imports' => true,
|
||||
'not_operator_with_successor_space' => true,
|
||||
'trailing_comma_in_multiline_array' => true,
|
||||
'phpdoc_scalar' => true,
|
||||
'unary_operator_spaces' => true,
|
||||
'binary_operator_spaces' => true,
|
||||
'blank_line_before_statement' => [
|
||||
'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
|
||||
],
|
||||
'phpdoc_single_line_var_spacing' => true,
|
||||
'phpdoc_var_without_name' => true,
|
||||
'class_attributes_separation' => [
|
||||
'elements' => [
|
||||
'method',
|
||||
],
|
||||
],
|
||||
'method_argument_space' => [
|
||||
'on_multiline' => 'ensure_fully_multiline',
|
||||
'keep_multiple_spaces_after_comma' => true,
|
||||
],
|
||||
'single_trait_insert_per_statement' => true,
|
||||
])
|
||||
->setFinder($finder);
|
||||
4
vendor/spatie/image-optimizer/.styleci.yml
vendored
Normal file
4
vendor/spatie/image-optimizer/.styleci.yml
vendored
Normal file
@@ -0,0 +1,4 @@
|
||||
preset: laravel
|
||||
|
||||
disabled:
|
||||
- single_class_element_per_statement
|
||||
107
vendor/spatie/image-optimizer/CHANGELOG.md
vendored
Normal file
107
vendor/spatie/image-optimizer/CHANGELOG.md
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
# Changelog
|
||||
|
||||
All notable changes to `image-optimizer` will be documented in this file
|
||||
|
||||
## 1.3.2 - 2020-11-28
|
||||
|
||||
- improve gifsicle (#131)
|
||||
|
||||
## 1.3.1 - 2020-10-20
|
||||
|
||||
- fix empty string setBinaryPath() (#129)
|
||||
|
||||
## 1.3.0 - 2020-10-10
|
||||
|
||||
- add support for php 8.0
|
||||
|
||||
## 1.2.1 - 2019-11-23
|
||||
|
||||
- allow symfony 5 components
|
||||
|
||||
## 1.2.0 - 2019-08-28
|
||||
|
||||
- add support for webp
|
||||
|
||||
## 1.1.6 - 2019-08-26
|
||||
|
||||
- do not export docs directory
|
||||
|
||||
## 1.1.5 - 2019-01-15
|
||||
|
||||
- fix for svg's
|
||||
- make compatible with PHPUnit 8
|
||||
|
||||
## 1.1.4 - 2019-01-14
|
||||
|
||||
- fix deprecation warning for passing strings to processes
|
||||
|
||||
## 1.1.3 - 2018-11-19
|
||||
|
||||
- require the fileinfo extension
|
||||
|
||||
## 1.1.2 - 2018-10-10
|
||||
|
||||
- make sure all optimizers use `binaryPath`
|
||||
|
||||
## 1.1.1 - 2018-09-10
|
||||
|
||||
- fix logger output
|
||||
|
||||
## 1.1.0 - 2018-06-05
|
||||
|
||||
- add `setBinaryPath`
|
||||
|
||||
## 1.0.14 - 2018-03-07
|
||||
|
||||
- support more symfony versions
|
||||
|
||||
## 1.0.13 - 2018-02-26
|
||||
|
||||
- added `text/plain` to the list of valid svg mime types
|
||||
|
||||
## 1.0.12. - 2018-02-21
|
||||
|
||||
- added `image/svg+xml` mime type
|
||||
|
||||
## 1.0.11 - 2018-02-08
|
||||
|
||||
- SVG mime type detection in PHP 7.2
|
||||
|
||||
## 1.0.10 - 2018-02-08
|
||||
|
||||
- Support symfony ^4.0
|
||||
- Support phpunit ^7.0
|
||||
|
||||
## 1.0.9 - 2017-11-03
|
||||
- fix shell command quotes
|
||||
|
||||
## 1.0.8 - 2017-09-14
|
||||
- allow Symfony 2 components
|
||||
- make Google Pagespeed tests pass
|
||||
|
||||
## 1.0.7 - 2017-07-29
|
||||
- lower requirements of dependencies
|
||||
|
||||
## 1.0.6 - 2017-07-10
|
||||
- fix `jpegoptim` parameters
|
||||
|
||||
## 1.0.4 - 2017-07-07
|
||||
|
||||
- make `setTimeout` chainable
|
||||
|
||||
## 1.0.3 - 2017-07-06
|
||||
|
||||
- fix `composer.json`
|
||||
|
||||
## 1.0.2 - 2017-07-06
|
||||
|
||||
- fix for Laravel 5.5 users
|
||||
|
||||
## 1.0.1 - 2017-07-06
|
||||
|
||||
- improve security
|
||||
|
||||
|
||||
## 1.0.0 - 2017-07-05
|
||||
|
||||
- initial release
|
||||
365
vendor/spatie/image-optimizer/README.md
vendored
Normal file
365
vendor/spatie/image-optimizer/README.md
vendored
Normal file
@@ -0,0 +1,365 @@
|
||||
# Easily optimize images using PHP
|
||||
|
||||
[](https://packagist.org/packages/spatie/image-optimizer)
|
||||

|
||||
[](https://packagist.org/packages/spatie/image-optimizer)
|
||||
|
||||
This package can optimize PNGs, JPGs, SVGs and GIFs by running them through a chain of various [image optimization tools](#optimization-tools). Here's how you can use it:
|
||||
|
||||
```php
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
|
||||
$optimizerChain = OptimizerChainFactory::create();
|
||||
|
||||
$optimizerChain->optimize($pathToImage);
|
||||
```
|
||||
|
||||
The image at `$pathToImage` will be overwritten by an optimized version which should be smaller. The package will automatically detect which optimization binaries are installed on your system and use them.
|
||||
|
||||
Here are some [example conversions](#example-conversions) that have been done by this package.
|
||||
|
||||
Loving Laravel? Then head over to [the Laravel specific integration](https://github.com/spatie/laravel-image-optimizer).
|
||||
|
||||
Using WordPress? Then try out [the WP CLI command](https://github.com/TypistTech/image-optimize-command).
|
||||
|
||||
## Support us
|
||||
|
||||
[<img src="https://github-ads.s3.eu-central-1.amazonaws.com/image-optimizer.jpg?t=1" width="419px" />](https://spatie.be/github-ad-click/image-optimizer)
|
||||
|
||||
We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).
|
||||
|
||||
We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).
|
||||
|
||||
## Installation
|
||||
|
||||
You can install the package via composer:
|
||||
|
||||
```bash
|
||||
composer require spatie/image-optimizer
|
||||
```
|
||||
|
||||
### Optimization tools
|
||||
|
||||
The package will use these optimizers if they are present on your system:
|
||||
|
||||
- [JpegOptim](http://freecode.com/projects/jpegoptim)
|
||||
- [Optipng](http://optipng.sourceforge.net/)
|
||||
- [Pngquant 2](https://pngquant.org/)
|
||||
- [SVGO](https://github.com/svg/svgo)
|
||||
- [Gifsicle](http://www.lcdf.org/gifsicle/)
|
||||
- [cwebp](https://developers.google.com/speed/webp/docs/precompiled)
|
||||
|
||||
Here's how to install all the optimizers on Ubuntu:
|
||||
|
||||
```bash
|
||||
sudo apt-get install jpegoptim
|
||||
sudo apt-get install optipng
|
||||
sudo apt-get install pngquant
|
||||
sudo npm install -g svgo
|
||||
sudo apt-get install gifsicle
|
||||
sudo apt-get install webp
|
||||
```
|
||||
|
||||
And here's how to install the binaries on MacOS (using [Homebrew](https://brew.sh/)):
|
||||
|
||||
```bash
|
||||
brew install jpegoptim
|
||||
brew install optipng
|
||||
brew install pngquant
|
||||
brew install svgo
|
||||
brew install gifsicle
|
||||
brew install webp
|
||||
```
|
||||
And here's how to install the binaries on Fedora/RHEL/CentOS:
|
||||
|
||||
```bash
|
||||
sudo dnf install epel-release
|
||||
sudo dnf install jpegoptim
|
||||
sudo dnf install optipng
|
||||
sudo dnf install pngquant
|
||||
sudo npm install -g svgo
|
||||
sudo dnf install gifsicle
|
||||
sudo dnf install libwebp-tools
|
||||
```
|
||||
|
||||
## Which tools will do what?
|
||||
|
||||
The package will automatically decide which tools to use on a particular image.
|
||||
|
||||
### JPGs
|
||||
|
||||
JPGs will be made smaller by running them through [JpegOptim](http://freecode.com/projects/jpegoptim). These options are used:
|
||||
- `-m85`: this will store the image with 85% quality. This setting [seems to satisfy Google's Pagespeed compression rules](https://webmasters.stackexchange.com/questions/102094/google-pagespeed-how-to-satisfy-the-new-image-compression-rules)
|
||||
- `--strip-all`: this strips out all text information such as comments and EXIF data
|
||||
- `--all-progressive`: this will make sure the resulting image is a progressive one, meaning it can be downloaded using multiple passes of progressively higher details.
|
||||
|
||||
### PNGs
|
||||
|
||||
PNGs will be made smaller by running them through two tools. The first one is [Pngquant 2](https://pngquant.org/), a lossy PNG compressor. We set no extra options, their defaults are used. After that we run the image through a second one: [Optipng](http://optipng.sourceforge.net/). These options are used:
|
||||
- `-i0`: this will result in a non-interlaced, progressive scanned image
|
||||
- `-o2`: this set the optimization level to two (multiple IDAT compression trials)
|
||||
|
||||
This package only supports Pngquant 2.5 and lower.
|
||||
|
||||
### SVGs
|
||||
|
||||
SVGs will be minified by [SVGO](https://github.com/svg/svgo). SVGO's default configuration will be used, with the omission of the `cleanupIDs` plugin because that one is known to cause troubles when displaying multiple optimized SVGs on one page.
|
||||
|
||||
Please be aware that SVGO can break your svg. You'll find more info on that in this [excellent blogpost](https://www.sarasoueidan.com/blog/svgo-tools/) by [Sara Soueidan](https://twitter.com/SaraSoueidan).
|
||||
|
||||
### GIFs
|
||||
|
||||
GIFs will be optimized by [Gifsicle](http://www.lcdf.org/gifsicle/). These options will be used:
|
||||
- `-O3`: this sets the optimization level to Gifsicle's maximum, which produces the slowest but best results
|
||||
|
||||
### WEBPs
|
||||
|
||||
WEBPs will be optimized by [Cwebp](https://developers.google.com/speed/webp/docs/cwebp). These options will be used:
|
||||
- `-m 6` for the slowest compression method in order to get the best compression.
|
||||
- `-pass 10` for maximizing the amount of analysis pass.
|
||||
- `-mt` multithreading for some speed improvements.
|
||||
- `-q 90` Quality factor that brings the least noticeable changes.
|
||||
|
||||
(Settings are original taken from [here](https://medium.com/@vinhlh/how-i-apply-webp-for-optimizing-images-9b11068db349))
|
||||
|
||||
## Usage
|
||||
|
||||
This is the default way to use the package:
|
||||
|
||||
``` php
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
|
||||
$optimizerChain = OptimizerChainFactory::create();
|
||||
|
||||
$optimizerChain->optimize($pathToImage);
|
||||
```
|
||||
|
||||
The image at `$pathToImage` will be overwritten by an optimized version which should be smaller.
|
||||
|
||||
The package will automatically detect which optimization binaries are installed on your system and use them.
|
||||
|
||||
To keep the original image, you can pass through a second argument`optimize`:
|
||||
```php
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
|
||||
$optimizerChain = OptimizerChainFactory::create();
|
||||
|
||||
$optimizerChain->optimize($pathToImage, $pathToOutput);
|
||||
```
|
||||
|
||||
In that example the package won't touch `$pathToImage` and write an optimized version to `$pathToOutput`.
|
||||
|
||||
### Setting a timeout
|
||||
|
||||
You can set the maximum of time in seconds that each individual optimizer in a chain can use by calling `setTimeout`:
|
||||
|
||||
```php
|
||||
$optimizerChain
|
||||
->setTimeout(10)
|
||||
->optimize($pathToImage);
|
||||
```
|
||||
|
||||
In this example each optimizer in the chain will get a maximum 10 seconds to do it's job.
|
||||
|
||||
### Creating your own optimization chains
|
||||
|
||||
If you want to customize the chain of optimizers you can do so by adding `Optimizer`s manually to an `OptimizerChain`.
|
||||
|
||||
Here's an example where we only want `optipng` and `jpegoptim` to be used:
|
||||
|
||||
```php
|
||||
use Spatie\ImageOptimizer\OptimizerChain;
|
||||
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
|
||||
use Spatie\ImageOptimizer\Optimizers\Pngquant;
|
||||
|
||||
$optimizerChain = (new OptimizerChain)
|
||||
->addOptimizer(new Jpegoptim([
|
||||
'--strip-all',
|
||||
'--all-progressive',
|
||||
]))
|
||||
|
||||
->addOptimizer(new Pngquant([
|
||||
'--force',
|
||||
]))
|
||||
```
|
||||
|
||||
Notice that you can pass the options an `Optimizer` should use to its constructor.
|
||||
|
||||
### Writing a custom optimizers
|
||||
|
||||
Want to use another command line utility to optimize your images? No problem. Just write your own optimizer. An optimizer is any class that implements the `Spatie\ImageOptimizer\Optimizers\Optimizer` interface:
|
||||
|
||||
```php
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
interface Optimizer
|
||||
{
|
||||
/**
|
||||
* Returns the name of the binary to be executed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function binaryName(): string;
|
||||
|
||||
/**
|
||||
* Determines if the given image can be handled by the optimizer.
|
||||
*
|
||||
* @param \Spatie\ImageOptimizer\Image $image
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canHandle(Image $image): bool;
|
||||
|
||||
/**
|
||||
* Set the path to the image that should be optimized.
|
||||
*
|
||||
* @param string $imagePath
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImagePath(string $imagePath);
|
||||
|
||||
/**
|
||||
* Set the options the optimizer should use.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions(array $options = []);
|
||||
|
||||
/**
|
||||
* Get the command that should be executed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommand(): string;
|
||||
}
|
||||
```
|
||||
|
||||
If you want to view an example implementation take a look at [the existing optimizers](https://github.com/spatie/image-optimizer/tree/master/src/Optimizers) shipped with this package.
|
||||
|
||||
You can easily add your optimizer by using the `addOptimizer` method on an `OptimizerChain`.
|
||||
|
||||
``` php
|
||||
use Spatie\ImageOptimizer\ImageOptimizerFactory;
|
||||
|
||||
$optimizerChain = OptimizerChainFactory::create();
|
||||
|
||||
$optimizerChain
|
||||
->addOptimizer(new YourCustomOptimizer())
|
||||
->optimize($pathToImage);
|
||||
```
|
||||
|
||||
## Logging the optimization process
|
||||
|
||||
By default the package will not throw any errors and just operate silently. To verify what the package is doing you can set a logger:
|
||||
|
||||
```php
|
||||
use Spatie\ImageOptimizer\OptimizerChainFactory;
|
||||
|
||||
$optimizerChain = OptimizerChainFactory::create();
|
||||
|
||||
$optimizerChain
|
||||
->useLogger(new MyLogger())
|
||||
->optimize($pathToImage);
|
||||
```
|
||||
|
||||
A logger is a class that implements `Psr\Log\LoggerInterface`. A good logging library that's fully compliant is [Monolog](https://github.com/Seldaek/monolog). The package will write to log which `Optimizers` are used, which commands are executed and their output.
|
||||
|
||||
## Example conversions
|
||||
|
||||
Here are some real life example conversions done by this package.
|
||||
|
||||
### png
|
||||
|
||||
Original: Photoshop 'Save for web' | PNG-24 with transparency<br>
|
||||
40 KB
|
||||
|
||||

|
||||
|
||||
Optimized<br>
|
||||
16 KB (40%)
|
||||
|
||||

|
||||
|
||||
### jpg
|
||||
|
||||
Original: Photoshop 'Save for web' | quality 60, optimized<br>
|
||||
547 KB
|
||||
|
||||

|
||||
|
||||
Optimized<br>
|
||||
525 KB (95%)
|
||||
|
||||

|
||||
|
||||
credits: Jeff Sheldon, via [Unsplash](https://unsplash.com)
|
||||
|
||||
### svg
|
||||
|
||||
Original: Illustrator | Web optimized SVG export<br>
|
||||
26 KB
|
||||
|
||||

|
||||
|
||||
Optimized<br>
|
||||
20 KB (76%)
|
||||
|
||||

|
||||
|
||||
### webp
|
||||
|
||||
Original: WebPonize<br>
|
||||
528 KB
|
||||
|
||||

|
||||
|
||||
Optimized<br>
|
||||
328 KB (89%)
|
||||
|
||||

|
||||
|
||||
credits: Jeff Sheldon, via [Unsplash](https://unsplash.com)
|
||||
|
||||
## Changelog
|
||||
|
||||
Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.
|
||||
|
||||
## Testing
|
||||
|
||||
``` bash
|
||||
composer test
|
||||
```
|
||||
|
||||
## Contributing
|
||||
|
||||
Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details.
|
||||
|
||||
## Security
|
||||
|
||||
If you discover any security related issues, please email freek@spatie.be instead of using the issue tracker.
|
||||
|
||||
## Postcardware
|
||||
|
||||
You're free to use this package (it's [MIT-licensed](.github/LICENSE.md)), but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.
|
||||
|
||||
Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.
|
||||
|
||||
We publish all received postcards [on our company website](https://spatie.be/en/opensource/postcards).
|
||||
|
||||
## Credits
|
||||
|
||||
- [Freek Van der Herten](https://github.com/freekmurze)
|
||||
- [All Contributors](../../contributors)
|
||||
|
||||
This package has been inspired by [psliwa/image-optimizer](https://github.com/psliwa/image-optimizer)
|
||||
|
||||
Emotional support provided by [Joke Forment](https://twitter.com/pronneur)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT). Please see [License File](.github/LICENSE.md) for more information.
|
||||
47
vendor/spatie/image-optimizer/composer.json
vendored
Normal file
47
vendor/spatie/image-optimizer/composer.json
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
{
|
||||
"name": "spatie/image-optimizer",
|
||||
"description": "Easily optimize images using PHP",
|
||||
"keywords": [
|
||||
"spatie",
|
||||
"image-optimizer"
|
||||
],
|
||||
"homepage": "https://github.com/spatie/image-optimizer",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Freek Van der Herten",
|
||||
"email": "freek@spatie.be",
|
||||
"homepage": "https://spatie.be",
|
||||
"role": "Developer"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^7.2|^8.0",
|
||||
"ext-fileinfo": "*",
|
||||
"psr/log": "^1.0",
|
||||
"symfony/process": "^4.2|^5.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^8.0|^9.0",
|
||||
"symfony/var-dumper": "^4.2|^5.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Spatie\\ImageOptimizer\\": "src"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Spatie\\ImageOptimizer\\Test\\": "tests"
|
||||
},
|
||||
"files": [
|
||||
"tests/helpers.php"
|
||||
]
|
||||
},
|
||||
"scripts": {
|
||||
"test": "vendor/bin/phpunit"
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
}
|
||||
}
|
||||
44
vendor/spatie/image-optimizer/src/DummyLogger.php
vendored
Normal file
44
vendor/spatie/image-optimizer/src/DummyLogger.php
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
class DummyLogger implements LoggerInterface
|
||||
{
|
||||
public function emergency($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function alert($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function critical($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function error($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function warning($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function notice($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function info($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function debug($message, array $context = [])
|
||||
{
|
||||
}
|
||||
|
||||
public function log($level, $message, array $context = [])
|
||||
{
|
||||
}
|
||||
}
|
||||
36
vendor/spatie/image-optimizer/src/Image.php
vendored
Normal file
36
vendor/spatie/image-optimizer/src/Image.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer;
|
||||
|
||||
use InvalidArgumentException;
|
||||
|
||||
class Image
|
||||
{
|
||||
protected $pathToImage = '';
|
||||
|
||||
public function __construct(string $pathToImage)
|
||||
{
|
||||
if (! file_exists($pathToImage)) {
|
||||
throw new InvalidArgumentException("`{$pathToImage}` does not exist");
|
||||
}
|
||||
|
||||
$this->pathToImage = $pathToImage;
|
||||
}
|
||||
|
||||
public function mime(): string
|
||||
{
|
||||
return mime_content_type($this->pathToImage);
|
||||
}
|
||||
|
||||
public function path(): string
|
||||
{
|
||||
return $this->pathToImage;
|
||||
}
|
||||
|
||||
public function extension(): string
|
||||
{
|
||||
$extension = pathinfo($this->pathToImage, PATHINFO_EXTENSION);
|
||||
|
||||
return strtolower($extension);
|
||||
}
|
||||
}
|
||||
47
vendor/spatie/image-optimizer/src/Optimizer.php
vendored
Normal file
47
vendor/spatie/image-optimizer/src/Optimizer.php
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer;
|
||||
|
||||
interface Optimizer
|
||||
{
|
||||
/**
|
||||
* Returns the name of the binary to be executed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function binaryName(): string;
|
||||
|
||||
/**
|
||||
* Determines if the given image can be handled by the optimizer.
|
||||
*
|
||||
* @param \Spatie\ImageOptimizer\Image $image
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function canHandle(Image $image): bool;
|
||||
|
||||
/**
|
||||
* Set the path to the image that should be optimized.
|
||||
*
|
||||
* @param string $imagePath
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setImagePath(string $imagePath);
|
||||
|
||||
/**
|
||||
* Set the options the optimizer should use.
|
||||
*
|
||||
* @param array $options
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setOptions(array $options = []);
|
||||
|
||||
/**
|
||||
* Get the command that should be executed.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCommand(): string;
|
||||
}
|
||||
116
vendor/spatie/image-optimizer/src/OptimizerChain.php
vendored
Normal file
116
vendor/spatie/image-optimizer/src/OptimizerChain.php
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer;
|
||||
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
class OptimizerChain
|
||||
{
|
||||
/* @var \Spatie\ImageOptimizer\Optimizer[] */
|
||||
protected $optimizers = [];
|
||||
|
||||
/** @var \Psr\Log\LoggerInterface */
|
||||
protected $logger;
|
||||
|
||||
/** @var int */
|
||||
protected $timeout = 60;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->useLogger(new DummyLogger());
|
||||
}
|
||||
|
||||
public function getOptimizers(): array
|
||||
{
|
||||
return $this->optimizers;
|
||||
}
|
||||
|
||||
public function addOptimizer(Optimizer $optimizer)
|
||||
{
|
||||
$this->optimizers[] = $optimizer;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptimizers(array $optimizers)
|
||||
{
|
||||
$this->optimizers = [];
|
||||
|
||||
foreach ($optimizers as $optimizer) {
|
||||
$this->addOptimizer($optimizer);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the amount of seconds each separate optimizer may use.
|
||||
*/
|
||||
public function setTimeout(int $timeoutInSeconds)
|
||||
{
|
||||
$this->timeout = $timeoutInSeconds;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function useLogger(LoggerInterface $log)
|
||||
{
|
||||
$this->logger = $log;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function optimize(string $pathToImage, string $pathToOutput = null)
|
||||
{
|
||||
if ($pathToOutput) {
|
||||
copy($pathToImage, $pathToOutput);
|
||||
|
||||
$pathToImage = $pathToOutput;
|
||||
}
|
||||
|
||||
$image = new Image($pathToImage);
|
||||
|
||||
$this->logger->info("Start optimizing {$pathToImage}");
|
||||
|
||||
foreach ($this->optimizers as $optimizer) {
|
||||
$this->applyOptimizer($optimizer, $image);
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyOptimizer(Optimizer $optimizer, Image $image)
|
||||
{
|
||||
if (! $optimizer->canHandle($image)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$optimizerClass = get_class($optimizer);
|
||||
|
||||
$this->logger->info("Using optimizer: `{$optimizerClass}`");
|
||||
|
||||
$optimizer->setImagePath($image->path());
|
||||
|
||||
$command = $optimizer->getCommand();
|
||||
|
||||
$this->logger->info("Executing `{$command}`");
|
||||
|
||||
$process = Process::fromShellCommandline($command);
|
||||
|
||||
$process
|
||||
->setTimeout($this->timeout)
|
||||
->run();
|
||||
|
||||
$this->logResult($process);
|
||||
}
|
||||
|
||||
protected function logResult(Process $process)
|
||||
{
|
||||
if (! $process->isSuccessful()) {
|
||||
$this->logger->error("Process errored with `{$process->getErrorOutput()}`");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->logger->info("Process successfully ended with output `{$process->getOutput()}`");
|
||||
}
|
||||
}
|
||||
56
vendor/spatie/image-optimizer/src/OptimizerChainFactory.php
vendored
Normal file
56
vendor/spatie/image-optimizer/src/OptimizerChainFactory.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer;
|
||||
|
||||
use Spatie\ImageOptimizer\Optimizers\Cwebp;
|
||||
use Spatie\ImageOptimizer\Optimizers\Gifsicle;
|
||||
use Spatie\ImageOptimizer\Optimizers\Jpegoptim;
|
||||
use Spatie\ImageOptimizer\Optimizers\Optipng;
|
||||
use Spatie\ImageOptimizer\Optimizers\Pngquant;
|
||||
use Spatie\ImageOptimizer\Optimizers\Svgo;
|
||||
|
||||
class OptimizerChainFactory
|
||||
{
|
||||
public static function create(array $config = []): OptimizerChain
|
||||
{
|
||||
$jpegQuality = '--max=85';
|
||||
$pngQuality = '--quality=85';
|
||||
if (isset($config['quality'])) {
|
||||
$jpegQuality = '--max='.$config['quality'];
|
||||
$pngQuality = '--quality='.$config['quality'];
|
||||
}
|
||||
|
||||
return (new OptimizerChain())
|
||||
->addOptimizer(new Jpegoptim([
|
||||
$jpegQuality,
|
||||
'--strip-all',
|
||||
'--all-progressive',
|
||||
]))
|
||||
|
||||
->addOptimizer(new Pngquant([
|
||||
$pngQuality,
|
||||
'--force',
|
||||
]))
|
||||
|
||||
->addOptimizer(new Optipng([
|
||||
'-i0',
|
||||
'-o2',
|
||||
'-quiet',
|
||||
]))
|
||||
|
||||
->addOptimizer(new Svgo([
|
||||
'--disable={cleanupIDs,removeViewBox}',
|
||||
]))
|
||||
|
||||
->addOptimizer(new Gifsicle([
|
||||
'-b',
|
||||
'-O3',
|
||||
]))
|
||||
->addOptimizer(new Cwebp([
|
||||
'-m 6',
|
||||
'-pass 10',
|
||||
'-mt',
|
||||
'-q 80',
|
||||
]));
|
||||
}
|
||||
}
|
||||
56
vendor/spatie/image-optimizer/src/Optimizers/BaseOptimizer.php
vendored
Normal file
56
vendor/spatie/image-optimizer/src/Optimizers/BaseOptimizer.php
vendored
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Optimizer;
|
||||
|
||||
abstract class BaseOptimizer implements Optimizer
|
||||
{
|
||||
public $options = [];
|
||||
|
||||
public $imagePath = '';
|
||||
|
||||
public $binaryPath = '';
|
||||
|
||||
public function __construct($options = [])
|
||||
{
|
||||
$this->setOptions($options);
|
||||
}
|
||||
|
||||
public function binaryName(): string
|
||||
{
|
||||
return $this->binaryName;
|
||||
}
|
||||
|
||||
public function setBinaryPath(string $binaryPath)
|
||||
{
|
||||
if (strlen($binaryPath) > 0 && substr($binaryPath, -1) !== DIRECTORY_SEPARATOR) {
|
||||
$binaryPath = $binaryPath.DIRECTORY_SEPARATOR;
|
||||
}
|
||||
|
||||
$this->binaryPath = $binaryPath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setImagePath(string $imagePath)
|
||||
{
|
||||
$this->imagePath = $imagePath;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setOptions(array $options = [])
|
||||
{
|
||||
$this->options = $options;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getCommand(): string
|
||||
{
|
||||
$optionString = implode(' ', $this->options);
|
||||
|
||||
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString} ".escapeshellarg($this->imagePath);
|
||||
}
|
||||
}
|
||||
24
vendor/spatie/image-optimizer/src/Optimizers/Cwebp.php
vendored
Normal file
24
vendor/spatie/image-optimizer/src/Optimizers/Cwebp.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Cwebp extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'cwebp';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
return $image->mime() === 'image/webp';
|
||||
}
|
||||
|
||||
public function getCommand(): string
|
||||
{
|
||||
$optionString = implode(' ', $this->options);
|
||||
|
||||
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString}"
|
||||
.' '.escapeshellarg($this->imagePath)
|
||||
.' -o '.escapeshellarg($this->imagePath);
|
||||
}
|
||||
}
|
||||
24
vendor/spatie/image-optimizer/src/Optimizers/Gifsicle.php
vendored
Normal file
24
vendor/spatie/image-optimizer/src/Optimizers/Gifsicle.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Gifsicle extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'gifsicle';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
return $image->mime() === 'image/gif';
|
||||
}
|
||||
|
||||
public function getCommand(): string
|
||||
{
|
||||
$optionString = implode(' ', $this->options);
|
||||
|
||||
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString}"
|
||||
.' -i '.escapeshellarg($this->imagePath)
|
||||
.' -o '.escapeshellarg($this->imagePath);
|
||||
}
|
||||
}
|
||||
15
vendor/spatie/image-optimizer/src/Optimizers/Jpegoptim.php
vendored
Normal file
15
vendor/spatie/image-optimizer/src/Optimizers/Jpegoptim.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Jpegoptim extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'jpegoptim';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
return $image->mime() === 'image/jpeg';
|
||||
}
|
||||
}
|
||||
15
vendor/spatie/image-optimizer/src/Optimizers/Optipng.php
vendored
Normal file
15
vendor/spatie/image-optimizer/src/Optimizers/Optipng.php
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Optipng extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'optipng';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
return $image->mime() === 'image/png';
|
||||
}
|
||||
}
|
||||
24
vendor/spatie/image-optimizer/src/Optimizers/Pngquant.php
vendored
Normal file
24
vendor/spatie/image-optimizer/src/Optimizers/Pngquant.php
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Pngquant extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'pngquant';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
return $image->mime() === 'image/png';
|
||||
}
|
||||
|
||||
public function getCommand(): string
|
||||
{
|
||||
$optionString = implode(' ', $this->options);
|
||||
|
||||
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString}"
|
||||
.' '.escapeshellarg($this->imagePath)
|
||||
.' --output='.escapeshellarg($this->imagePath);
|
||||
}
|
||||
}
|
||||
33
vendor/spatie/image-optimizer/src/Optimizers/Svgo.php
vendored
Normal file
33
vendor/spatie/image-optimizer/src/Optimizers/Svgo.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace Spatie\ImageOptimizer\Optimizers;
|
||||
|
||||
use Spatie\ImageOptimizer\Image;
|
||||
|
||||
class Svgo extends BaseOptimizer
|
||||
{
|
||||
public $binaryName = 'svgo';
|
||||
|
||||
public function canHandle(Image $image): bool
|
||||
{
|
||||
if ($image->extension() !== 'svg') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return in_array($image->mime(), [
|
||||
'text/html',
|
||||
'image/svg',
|
||||
'image/svg+xml',
|
||||
'text/plain',
|
||||
]);
|
||||
}
|
||||
|
||||
public function getCommand(): string
|
||||
{
|
||||
$optionString = implode(' ', $this->options);
|
||||
|
||||
return "\"{$this->binaryPath}{$this->binaryName}\" {$optionString}"
|
||||
.' --input='.escapeshellarg($this->imagePath)
|
||||
.' --output='.escapeshellarg($this->imagePath);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user