Skip to content

Commit 76d70cd

Browse files
committed
Batman! (this commit has no parents)
0 parents  commit 76d70cd

25 files changed

+984
-0
lines changed

.gitattributes

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Path-based git attributes
2+
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
3+
4+
# Ignore everything.
5+
/* export-ignore
6+
7+
# Export white-listed production code only.
8+
/src -export-ignore
9+
/composer.json -export-ignore
10+
/command.php -export-ignore
11+
/LICENSE.md -export-ignore
12+
/README.md -export-ignore

.github_changelog_generator

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
future-release=0.1.0

.gitignore

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
.DS_Store
2+
wp-cli.local.yml
3+
node_modules/
4+
vendor/
5+
*.zip
6+
*.tar.gz
7+
*.swp
8+
*.txt
9+
*.log
10+
composer.lock
11+
12+
### Codeception ###
13+
/codeception.yml
14+
/tests/*.suite.yml
15+
/tests/_output/*
16+
/tests/_support/_generated/
17+
18+
### PhpStorm ###
19+
/.idea/

.styleci.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
preset: recommended
2+
3+
finder:
4+
exclude:
5+
- "lib"
6+
7+
disabled:
8+
- align_double_arrow
9+
- concat_without_spaces
10+
- new_with_braces
11+
- no_blank_lines_after_phpdoc
12+
- no_spaces_inside_offset
13+
- phpdoc_no_package
14+
- phpdoc_summary
15+
- simplified_null_return
16+
- trim_array_spaces
17+
18+
enabled:
19+
- concat_with_spaces
20+
- declare_strict_types
21+
- dir_constant
22+
- is_null
23+
- linebreak_after_opening_tag
24+
- modernize_types_casting
25+
- no_empty_comment
26+
- no_php4_constructor
27+
- no_short_echo_tag
28+
- no_useless_else
29+
- not_operator_with_successor_space
30+
- php_unit_construct
31+
- php_unit_dedicate_assert
32+
- phpdoc_link_to_see
33+
- phpdoc_property
34+
- phpdoc_return_self_reference
35+
- pow_to_exponentiation
36+
- random_api_migration
37+
- return_type_declaration
38+
- semicolon_after_instruction
39+
- single_line_class_definition
40+
- strict_comparison
41+
- strict_param
42+
- ternary_to_null_coalescing
43+
- unalign_double_arrow

.travis.yml

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
language: php
2+
3+
branches:
4+
only:
5+
- master
6+
- /^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/
7+
8+
cache:
9+
directories:
10+
- $HOME/.composer/cache/files
11+
12+
notifications:
13+
email:
14+
on_success: never
15+
on_failure: change
16+
17+
cache:
18+
directories:
19+
- $HOME/.composer/cache
20+
21+
php:
22+
- 7.1
23+
- 7.2
24+
- nightly
25+
26+
env:
27+
global:
28+
- COMPOSER_NO_INTERACTION=1
29+
- PATH="$TRAVIS_BUILD_DIR/vendor/bin:$PATH"
30+
31+
matrix:
32+
allow_failures:
33+
- php: nightly
34+
fast_finish: true
35+
36+
before_install:
37+
- |
38+
# Remove Xdebug for a huge performance increase:
39+
if [ -f ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ]; then
40+
phpenv config-rm xdebug.ini
41+
else
42+
echo "xdebug.ini does not exist"
43+
fi
44+
45+
install:
46+
- travis_retry composer install --prefer-dist --no-suggest
47+
48+
before_script:
49+
- composer validate
50+
51+
script:
52+
- composer test
53+
- composer check-style

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Contributing
2+
============
3+
4+
We appreciate you taking the initiative to contribute to this project.
5+
6+
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.
7+
8+
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.

LICENSE.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2018 The contributors.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

+157
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# typisttech/image-optimize-command
2+
3+
[![Latest Stable Version](https://poser.pugx.org/typisttech/image-optimize-command/v/stable)](https://packagist.org/packages/typisttech/image-optimize-command)
4+
[![Total Downloads](https://poser.pugx.org/typisttech/image-optimize-command/downloads)](https://packagist.org/packages/typisttech/image-optimize-command)
5+
[![Build Status](https://travis-ci.org/TypistTech/image-optimize-command.svg?branch=master)](https://travis-ci.org/TypistTech/image-optimize-command)
6+
[![PHP Versions Tested](http://php-eye.com/badge/typisttech/image-optimize-command/tested.svg)](https://travis-ci.org/TypistTech/image-optimize-command)
7+
[![StyleCI](https://styleci.io/repos/119003751/shield?branch=master)](https://styleci.io/repos/119003751)
8+
[![Dependency Status](https://gemnasium.com/badges/github.com/TypistTech/image-optimize-command.svg)](https://gemnasium.com/github.com/TypistTech/image-optimize-command)
9+
[![License](https://poser.pugx.org/typisttech/image-optimize-command/license)](https://packagist.org/packages/typisttech/image-optimize-command)
10+
[![Donate via PayPal](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://typist.tech/donate/image-optimize-command/)
11+
[![Hire Typist Tech](https://img.shields.io/badge/Hire-Typist%20Tech-ff69b4.svg)](https://typist.tech/contact/)
12+
13+
Easily optimize images using WP CLI.
14+
15+
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
16+
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
17+
18+
19+
- [Using](#using)
20+
- [Installing](#installing)
21+
- [Optimization tools](#optimization-tools)
22+
- [FAQs](#faqs)
23+
- [What kind of optimization it does?](#what-kind-of-optimization-it-does)
24+
- [Why the optimize command stopped for no reason?](#why-the-optimize-command-stopped-for-no-reason)
25+
- [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+
- [Why my GIFs stopped animating?](#why-my-gifs-stopped-animating)
27+
- [Is it for everyone?](#is-it-for-everyone)
28+
- [Support](#support)
29+
- [Why don't you hire me?](#why-dont-you-hire-me)
30+
- [Want to help in other way? Want to be a sponsor?](#want-to-help-in-other-way-want-to-be-a-sponsor)
31+
- [Credits](#credits)
32+
- [Contributing](#contributing)
33+
- [Reporting a bug](#reporting-a-bug)
34+
- [Creating a pull request](#creating-a-pull-request)
35+
36+
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
37+
38+
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).
39+
40+
## Using
41+
42+
```bash
43+
# Optimize 10 attachments
44+
$ wp image-optimize run --limit=10
45+
46+
# Optimize after thumbnail regeneration
47+
$ wp media regenerate --yes
48+
$ wp image-optimize reset --yes
49+
$ wp image-optimize run --limit=9999999
50+
```
51+
52+
## Installing
53+
54+
Installing this package requires WP-CLI v1.4.1 or greater. Update to the latest stable release with `wp cli update`.
55+
56+
Once you've done so, you can install this package with:
57+
58+
wp package install https://github.com/TypistTech/image-optimize-command.git
59+
60+
### Optimization tools
61+
62+
Under the hood, `image-optimize-command` invokes [spatie/image-optimizer](https://github.com/spatie/image-optimizer) which requires these binaries installed:
63+
64+
- [JpegOptim](http://freecode.com/projects/jpegoptim)
65+
- [Optipng](http://optipng.sourceforge.net/)
66+
- [Pngquant 2](https://pngquant.org/)
67+
- [SVGO](https://github.com/svg/svgo)
68+
- [Gifsicle](http://www.lcdf.org/gifsicle/)
69+
70+
Check spatie/image-optimizer's readme for [install instructions](https://github.com/spatie/image-optimizer#optimization-tools).
71+
72+
Note that WordPress doesn't support SVG out of the box. You can omit [SVGO](https://github.com/svg/svgo).
73+
74+
## FAQs
75+
76+
### What kind of optimization it does?
77+
78+
Mostly applying compression, removing metadata and reducing the number of colors to PNGs, JPGs, SVGs and GIFs. The package is smart enough pick the right tool for the right image.
79+
80+
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)
81+
82+
### Why the optimize command stopped for no reason?
83+
84+
Expected result:
85+
```bash
86+
$ wp image-optimize run --limit=10
87+
Success: 10 unoptimized attachment(s) found. Starting...
88+
...omitted...
89+
Success 10 attachment(s) optimized
90+
91+
$ wp image-optimize run --limit=10
92+
No unoptimized attachment found. Abort!
93+
```
94+
95+
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:
96+
```bash
97+
$ wp media regenerate --yes
98+
$ wp image-optimize reset --yes
99+
$ wp image-optimize run --limit=9999999
100+
```
101+
102+
### Does running `wp image-optimize run` multiple times trigger multiple optimization for the same attachments?
103+
104+
No, by default, optimized flags (meta fields) are given to attachments after optimization (`$ wp image-optimize run --limit=999`). This is to prevent re-optimizing an already optimized attachment. If you changed the image files (e.g.: resize / regenerate thumbnail), you must first reset their meta flags.
105+
106+
### Why my GIFs stopped animating?
107+
108+
> When you upload an image using the media uploader, WordPress automatically creates several copies of that image in different sizes...When creating new image sizes for animated GIFs, **WordPress ends up saving only the first frame of the GIF**...
109+
> --- [wpbeginner](http://www.wpbeginner.com/wp-tutorials/how-to-add-animated-gifs-in-wordpress/)
110+
111+
Luckily for you, Lasse M. Tvedt showed how to disable stop WordPress from resizing GIFs on [StackExchange](https://wordpress.stackexchange.com/a/229724).
112+
113+
### Is it for everyone?
114+
115+
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.
116+
117+
## Support
118+
119+
Love `image-optimize-command`? Help me maintain it, a [donation here](https://typist.tech/donation/) can help with it.
120+
121+
### Why don't you hire me?
122+
123+
Ready to take freelance WordPress jobs. Contact me via the contact form [here](https://typist.tech/contact/) or, via email [[email protected]](mailto:[email protected])
124+
125+
### Want to help in other way? Want to be a sponsor?
126+
127+
Contact: [Tang Rufus](mailto:[email protected])
128+
129+
## Credits
130+
131+
[`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/).
132+
133+
Full list of contributors can be found [here](https://github.com/TypistTech/image-optimize-command/graphs/contributors).
134+
135+
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.
136+
137+
## Contributing
138+
139+
We appreciate you taking the initiative to contribute to this project.
140+
141+
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.
142+
143+
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.
144+
145+
### Reporting a bug
146+
147+
Think you’ve found a bug? We’d love for you to help us get it fixed.
148+
149+
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.
150+
151+
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/).
152+
153+
### Creating a pull request
154+
155+
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.
156+
157+
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.

codeception.dist.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace: TypistTech\ImageOptimizeCommand
2+
paths:
3+
tests: tests
4+
output: tests/_output
5+
data: tests/_data
6+
support: tests/_support
7+
envs: tests/_envs
8+
actor_suffix: Tester
9+
settings:
10+
shuffle: true
11+
extensions:
12+
enabled:
13+
- Codeception\Extension\RunFailed

command.php

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TypistTech\ImageOptimizeCommand;
6+
7+
use WP_CLI;
8+
9+
if (! class_exists('WP_CLI')) {
10+
return;
11+
}
12+
13+
$autoload = __DIR__ . '/vendor/autoload.php';
14+
if (file_exists($autoload)) {
15+
require_once $autoload;
16+
}
17+
18+
WP_CLI::add_command('image-optimize', __NAMESPACE__ . '\ImageOptimizeCommand');

0 commit comments

Comments
 (0)