You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -13,52 +14,72 @@ Easily optimize images using WP CLI.
13
14
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
14
15
15
16
16
-
-[Using](#using)
17
+
-[Usage](#usage)
17
18
-[Installing](#installing)
18
19
-[Optimization tools](#optimization-tools)
20
+
-[Use Cases](#use-cases)
21
+
-[First use](#first-use)
22
+
-[Restore the originals](#restore-the-originals)
23
+
-[Migrate from image-optimize-command v0.1.x](#migrate-from-image-optimize-command-v01x)
19
24
-[FAQs](#faqs)
20
25
-[What kind of optimization it does?](#what-kind-of-optimization-it-does)
21
-
-[Why the optimize command stopped for no reason?](#why-the-optimize-command-stopped-for-no-reason)
22
-
-[Does running `wp image-optimize run` multiple times trigger multiple optimization for the same attachments?](#does-running-wp-image-optimize-run-multiple-times-trigger-multiple-optimization-for-the-same-attachments)
26
+
-[Can I customize the optimization?](#can-i-customize-the-optimization)
27
+
-[Does running `wp image-optimize attachment / batch` multiple times trigger multiple optimization for the same attachments?](#does-running-wp-image-optimize-attachment--batch-multiple-times-trigger-multiple-optimization-for-the-same-attachments)
23
28
-[Will the images look different after optimization?](#will-the-images-look-different-after-optimization)
24
29
-[Why my GIFs stopped animating?](#why-my-gifs-stopped-animating)
30
+
-[Can I use this on managed hosting?](#can-i-use-this-on-managed-hosting)
31
+
-[Do I have to install `SVGO`?](#do-i-have-to-install-svgo)
32
+
-[`PHP Fatal error: Allowed memory size of 999999 bytes exhausted (tried to allocate 99 bytes)`](#php-fatal-error-allowed-memory-size-of-999999-bytes-exhausted-tried-to-allocate-99-bytes)
25
33
-[Does it has any limitation?](#does-it-has-any-limitation)
34
+
-[Will you add support for older PHP versions?](#will-you-add-support-for-older-php-versions)
26
35
-[Is it for everyone?](#is-it-for-everyone)
27
36
-[It looks awesome. Where can I find some more goodies like this?](#it-looks-awesome-where-can-i-find-some-more-goodies-like-this)
28
37
-[This package isn't on wp.org. Where can I give a :star::star::star::star::star: review?](#this-package-isnt-on-wporg-where-can-i-give-a-starstarstarstarstar-review)
29
38
-[Support](#support)
30
39
-[Why don't you hire me?](#why-dont-you-hire-me)
31
40
-[Want to help in other way? Want to be a sponsor?](#want-to-help-in-other-way-want-to-be-a-sponsor)
41
+
-[Running the Tests](#running-the-tests)
42
+
-[Feedback](#feedback)
43
+
-[Change log](#change-log)
44
+
-[Security](#security)
32
45
-[Credits](#credits)
33
-
-[Contributing](#contributing)
34
-
-[Reporting a bug](#reporting-a-bug)
35
-
-[Creating a pull request](#creating-a-pull-request)
46
+
-[License](#license)
36
47
37
48
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
38
49
39
50
WP CLI wrapper for [spatie/image-optimizer](https://github.com/spatie/image-optimizer). **Optimizing PNGs, JPGs, SVGs and GIFs by running them through a chain of various image [optimization tools](#optimization-tools).** Check this project's [introductory blog post](https://typist.tech/articles/easily-optimize-wordpress-images-using-wp-cli-and-some-binaries/) about why I built it.
40
51
41
52
42
-
## Using
53
+
## Usage
43
54
44
55
```bash
45
-
#Optimize 10 attachments
46
-
$ wp image-optimize run --limit=10
56
+
#optimize specific attachments
57
+
$ wp image-optimize attachment 123 223 323
47
58
48
-
# Optimize after thumbnail regeneration
49
-
$ wp media regenerate --yes
50
-
$ wp image-optimize reset --yes
51
-
$ wp image-optimize run --limit=9999999
59
+
# optimize certain number of attachments
60
+
$ wp image-optimize batch --limit=20
61
+
62
+
# restore the full sized images of specific attachments.
63
+
$ wp image-optimize restore 123 223 323
64
+
$ wp media regenerate 123 223 323
65
+
66
+
# restore all full sized images and drop all meta flags
67
+
$ wp image-optimize reset
68
+
$ wp media regenerate
69
+
70
+
# learn more
71
+
$ wp help image-optimize
72
+
$ wp help image-optimize <subcommand>
52
73
```
53
74
54
75
## Installing
55
76
56
-
Installing this package requires WP-CLI v1.4.1 or greater. Update to the latest stable release with `wp cli update`.
77
+
Installing this package requires [WP-CLI v2.0.0](https://wp-cli.org/) or greater. Update to the latest stable release with `wp cli update`.
57
78
58
79
Once you've done so, you can install this package with:
@@ -74,7 +95,50 @@ Under the hood, `image-optimize-command` invokes [spatie/image-optimizer](https:
74
95
Check spatie/image-optimizer's readme for [install instructions](https://github.com/spatie/image-optimizer#optimization-tools).
75
96
76
97
Note that [WordPress doesn't support SVG](https://core.trac.wordpress.org/ticket/24251) out of the box. You can omit [SVGO](https://github.com/svg/svgo).
77
-
However, if you have [enabled WordPress SVG support](https://kinsta.com/blog/wordpress-svg/?kaid=CGCHYHJJJMMF), you must install SVGO. Otherwise, the command will fail.
98
+
However, if you have [enabled WordPress SVG support](https://kinsta.com/blog/wordpress-svg/?kaid=CGCHYHJJJMMF) and uploaded SVGs to WordPress media library, you must install SVGO. Otherwise, the command will fail.
99
+
100
+
## Use Cases
101
+
102
+
### First use
103
+
104
+
This command optimize both the full sized image(the one you uploaded) and the thumbnails(WordPress auto-resize these images for you).
105
+
106
+
Chances are the thumbnails are missing or never generated:
107
+
108
+
- theme switched after upload
109
+
- plugins activated after upload
110
+
- deleted the images from disk but not updated WordPress' database
111
+
112
+
Simplest solution is to regenerate thumbnails then optimize:
113
+
114
+
```bash
115
+
$ wp media regenerate
116
+
$ wp image-optimize batch --limit=9999999
117
+
```
118
+
119
+
### Restore the originals
120
+
121
+
This command backs up the full sized images before optimization. If you want to restore them:
122
+
123
+
```bash
124
+
# optimize
125
+
$ wp image-optimize attachment 123
126
+
127
+
# restore the full sized image
128
+
$ wp image-optimize restore 123
129
+
# regenerate the thumbnails from the original full sized image
130
+
$ wp media regenerate 123
131
+
```
132
+
133
+
### Migrate from image-optimize-command v0.1.x
134
+
135
+
Starting from v0.2, this command backs up the full sized images before optimization. To migrate from image-optimize-command v0.1.x:
136
+
137
+
```bash
138
+
$ wp image-optimize reset
139
+
$ wp media regenerate
140
+
$ wp image-optimize batch --limit=9999999
141
+
```
78
142
79
143
## FAQs
80
144
@@ -84,30 +148,30 @@ Mostly applying compression, removing metadata and reducing the number of colors
84
148
85
149
Check Freek Van der Herten's [article](https://murze.be/easily-optimize-images-using-php-and-some-binaries) explaining `spatie/image-optimizer`'s [*sane default configuration*](https://github.com/spatie/image-optimizer/blob/124da0d/src/OptimizerChainFactory.php).
86
150
87
-
### Why the optimize command stopped for no reason?
If it stopped halfway, most likely you deleted the images from disk but not updated WordPress' database. Simplest solution is to regenerate thumbnails then optimize again:
104
-
```bash
105
-
$ wp media regenerate --yes
106
-
$ wp image-optimize reset --yes
107
-
$ wp image-optimize run --limit=9999999
155
+
```php
156
+
use Spatie\ImageOptimizer\OptimizerChain;
157
+
158
+
add_filter('typist_tech_image_optimized_optimizer_chain', function (OptimizerChain $optimizerChain): OptimizerChain {
### Does running `wp image-optimize run` multiple times trigger multiple optimization for the same attachments?
174
+
### Does running `wp image-optimize attachment / batch` multiple times trigger multiple optimization for the same attachments?
111
175
112
176
No.
113
177
@@ -127,10 +191,38 @@ See [spatie/image-optimizer](https://github.com/spatie/image-optimizer#which-too
127
191
128
192
Luckily for you, Lasse M. Tvedt showed how to stop WordPress from resizing GIFs on [StackExchange](https://wordpress.stackexchange.com/a/229724).
129
193
194
+
### Can I use this on managed hosting?
195
+
196
+
No, you can't use this on managed hosting such as [Kinsta](http://bit.ly/kinsta-com) or [WP Engine](https://typist.tech/go/wp-engine) because they don't allow you to install those binaries.
197
+
198
+
If you must use it on managed hosting, [hire a developer](https://typist.tech/contact/) to add SaaS provider integration:
Yes, if you have [enabled WordPress SVG support](https://kinsta.com/blog/wordpress-svg/?kaid=CGCHYHJJJMMF) and uploaded SVGs to WordPress media library.
209
+
210
+
No, if you don't have any SVGs in WordPress media library.
211
+
212
+
### `PHP Fatal error: Allowed memory size of 999999 bytes exhausted (tried to allocate 99 bytes)`
213
+
214
+
This is a common WP CLI issue. See: [https://bit.ly/wpclimem](https://make.wordpress.org/cli/handbook/common-issues/#php-fatal-error-allowed-memory-size-of-999999-bytes-exhausted-tried-to-allocate-99-bytes)
215
+
130
216
### Does it has any limitation?
131
217
132
218
No, unlike other SaaS alternatives, this package runs on your server without any limitation on file sizes or monthly quota. Totally free of charge.
133
219
220
+
### Will you add support for older PHP versions?
221
+
222
+
Never! This plugin will only works on [actively supported PHP versions](https://secure.php.net/supported-versions.php).
223
+
224
+
Don't use it on **end of life** or **security fixes only** PHP versions.
225
+
134
226
### Is it for everyone?
135
227
136
228
No, it comes at a cost. Optimization is CPU intensive. Expect CPU usage rockets up to 100% during optimization. Schedule it to run at late night in small batches.
@@ -164,32 +256,37 @@ Ready to take freelance WordPress jobs. Contact me via the contact form [here](h
[`image-optimize-command`](https://github.com/TypistTech/image-optimize-command) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://twitter.com/TangRufus), freelance developer for [hire](https://www.typist.tech/contact/).
261
+
Run the tests:
170
262
171
-
Full list of contributors can be found [here](https://github.com/TypistTech/image-optimize-command/graphs/contributors).
263
+
```bash
264
+
$ composer test
265
+
$ composer check-style
266
+
```
172
267
173
-
Special thanks to [Freek Van der Herten](https://github.com/freekmurze/) whose [spatie/image-optimizer](https://github.com/spatie/image-optimizer) package makes this project possible.
268
+
## Feedback
174
269
175
-
## Contributing
270
+
**Please provide feedback!** We want to make this library useful in as many projects as possible.
271
+
Please submit an [issue](https://github.com/TypistTech/image-optimize-command/issues/new) and point out what you do and don't like, or fork the project and make suggestions.
272
+
**No issue is too small.**
176
273
177
-
We appreciate you taking the initiative to contribute to this project.
274
+
## Change log
178
275
179
-
Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.
276
+
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
180
277
181
-
For a more thorough introduction, [check out WP-CLI's guide to contributing](https://make.wordpress.org/cli/handbook/contributing/). This package follows those policy and guidelines.
278
+
## Security
182
279
183
-
### Reporting a bug
280
+
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
184
281
185
-
Think you’ve found a bug? We’d love for you to help us get it fixed.
282
+
## Credits
186
283
187
-
Before you create a new issue, you should [search existing issues](https://github.com/typisttech/image-optimize-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.
284
+
[`image-optimize-command`](https://github.com/TypistTech/image-optimize-command) is a [Typist Tech](https://typist.tech) project and maintained by [Tang Rufus](https://twitter.com/TangRufus), freelance developer for [hire](https://www.typist.tech/contact/).
188
285
189
-
Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/typisttech/image-optimize-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).
286
+
Full list of contributors can be found [here](https://github.com/TypistTech/image-optimize-command/graphs/contributors).
190
287
191
-
### Creating a pull request
288
+
Special thanks to [Freek Van der Herten](https://github.com/freekmurze/) whose [spatie/image-optimizer](https://github.com/spatie/image-optimizer) package makes this project possible.
192
289
193
-
Want to contribute a new feature? Please first [open a new issue](https://github.com/typisttech/image-optimize-command/issues/new) to discuss whether the feature is a good fit for the project.
290
+
## License
194
291
195
-
Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.
292
+
The MIT License (MIT). Please see [License File](./LICENSE.md) for more information.
0 commit comments