├── .editorconfig
├── .gitignore
├── .styleci.yml
├── LICENSE.md
├── README.md
├── composer.json
├── config
└── laravel-webp.php
└── src
├── Cwebp.php
├── Exceptions
├── CwebpShellExecutionFailed.php
├── DriverIsNotSupportedException.php
└── ImageMimeNotSupportedException.php
├── Facades
└── Webp.php
├── Interfaces
└── WebpInterface.php
├── PhpGD.php
├── Traits
└── WebpTrait.php
├── Webp.php
└── WebpServiceProvider.php
/.editorconfig:
--------------------------------------------------------------------------------
1 | ; This file is for unifying the coding style for different editors and IDEs.
2 | ; More information at http://editorconfig.org
3 |
4 | root = true
5 |
6 | [*]
7 | charset = utf-8
8 | indent_size = 4
9 | indent_style = space
10 | end_of_line = lf
11 | insert_final_newline = true
12 | trim_trailing_whitespace = true
13 |
14 | [*.md]
15 | trim_trailing_whitespace = false
16 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | PULL_REQUEST_TEMPLATE.md
2 | prefill.php
3 | .idea
4 | vendor
5 | composer.lock
6 |
--------------------------------------------------------------------------------
/.styleci.yml:
--------------------------------------------------------------------------------
1 | preset: psr2
2 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | Copyright (c) 2017 :author_name <:author_email>
4 |
5 | > Permission is hereby granted, free of charge, to any person obtaining a copy
6 | > of this software and associated documentation files (the "Software"), to deal
7 | > in the Software without restriction, including without limitation the rights
8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | > copies of the Software, and to permit persons to whom the Software is
10 | > furnished to do so, subject to the following conditions:
11 | >
12 | > The above copyright notice and this permission notice shall be included in
13 | > all copies or substantial portions of the Software.
14 | >
15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | > THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [
](https://supportukrainenow.org)
2 |
3 | ## WebP (.webp) comes to Laravel
4 |
5 | [![Latest Version on Packagist][ico-version]][link-packagist]
6 | [![Software License][ico-license]](LICENSE.md)
7 | [![Total Downloads][ico-downloads]][link-downloads]
8 |
9 | ## About
10 |
11 | WebP is a modern image format that provides superior lossless and lossy compression for images on the web. Using WebP,
12 | webmasters and web developers can create smaller, richer images that make the web faster.
13 |
14 | WebP lossless images are 26% smaller in size compared to PNGs. WebP lossy images are 25-34% smaller than comparable JPEG
15 | images at equivalent SSIM quality index.
16 |
17 | Lossless WebP supports transparency (also known as alpha channel) at a cost of just 22% additional bytes. For cases when
18 | lossy RGB compression is acceptable, lossy WebP also supports transparency, typically providing 3× smaller file sizes
19 | compared to PNG.
20 |
21 | `cwebp` compresses an image using the WebP format. Input format can be either `PNG`, `JPEG`, `TIFF`, `WebP` or
22 | raw `Y'CbCr` samples.
23 |
24 | ## Before Installation
25 |
26 | ### New Driver Is Available: `php-gd`
27 |
28 | Currently, supports 2 drivers:
29 | * `php-gd` - Only needs `gd` - PHP extension to be installed
30 | * `cwebp` - uses Google native `cwebp` cli command
31 |
32 | Note: If you choose to use cwebp driver you will need to install WebP before installing this package.\
33 | For more information you can visit this [page](https://developers.google.com/speed/webp/)
34 |
35 | ## Install
36 |
37 | Via Composer
38 |
39 | ```bash
40 | $ composer require buglinjo/laravel-webp
41 | ```
42 |
43 | #### For Laravel <= 5.4
44 |
45 | After updating composer, add the ServiceProvider to the providers array in config/app.php
46 |
47 | ```php
48 | Buglinjo\LaravelWebp\WebpServiceProvider::class,
49 | ```
50 |
51 | You can use the facade for shorter code. Add this to your aliases:
52 |
53 | ```php
54 | 'Webp' => Buglinjo\LaravelWebp\Facades\Webp::class,
55 | ```
56 |
57 | #### Publish config file
58 |
59 | You will need to publish config file to add `cwebp` global path.
60 |
61 | ```
62 | php artisan vendor:publish --provider="Buglinjo\LaravelWebp\WebpServiceProvider" --tag=config
63 | ```
64 |
65 | In `config/laravel-webp.php` config file you should set `cwebp` global path.
66 |
67 | ```php
68 | return [
69 | /*
70 | |--------------------------------------------------------------------------
71 | | Default Quality
72 | |--------------------------------------------------------------------------
73 | |
74 | | This is a default quality unless you provide while generation of the WebP
75 | |
76 | */
77 | 'default_quality' => 70,
78 |
79 | /*
80 | |--------------------------------------------------------------------------
81 | | Default Driver
82 | |--------------------------------------------------------------------------
83 | |
84 | | This is a default image processing driver. Available: ['cwebp', 'php-gd']
85 | |
86 | */
87 | 'default_driver' => 'php-gd',
88 |
89 | /*
90 | |--------------------------------------------------------------------------
91 | | Drivers
92 | |--------------------------------------------------------------------------
93 | |
94 | | Available drivers which can be selected
95 | |
96 | */
97 | 'drivers' => [
98 |
99 | /*
100 | |--------------------------------------------------------------------------
101 | | Cwebp Driver
102 | |--------------------------------------------------------------------------
103 | |
104 | | If you choose cwebp driver it is required to specify the path to the executable.
105 | |
106 | */
107 | 'cwebp' => [
108 | 'path' => '/usr/local/bin/cwebp',
109 | ],
110 |
111 | /*
112 | |--------------------------------------------------------------------------
113 | | Cwebp Driver
114 | |--------------------------------------------------------------------------
115 | |
116 | | If you choose PHP GD driver no configuration is necessary.
117 | |
118 | */
119 | 'php-gd' => [
120 | //
121 | ],
122 | ],
123 | ];
124 | ```
125 |
126 | ## Usage
127 |
128 | ```php
129 | Webp::make()->save(