All Projects → TypistTech → Image Optimize Command

TypistTech / Image Optimize Command

Licence: mit
Easily optimize images using WP CLI

Projects that are alternatives of or similar to Image Optimize Command

Image Optimizer
Easily optimize images using PHP
Stars: ✭ 2,127 (+1441.3%)
Mutual labels:  image, optimizer, performance
Crunch
Crunch is a tool for lossy PNG image file optimization. It combines selective bit depth, color type, and color palette reduction with zopfli DEFLATE compression algorithm encoding using the pngquant and zopflipng PNG optimization tools. This approach leads to a significant file size gain relative to lossless approaches at the expense of a relatively modest decrease in image quality (see example images below).
Stars: ✭ 3,074 (+2127.54%)
Mutual labels:  image, pngquant, compression
Image Optimizer
Image optimization / compression library. This library is able to optimize png, jpg and gif files in very easy and handy way. It uses optipng, pngquant, pngcrush, pngout, gifsicle, jpegoptim and jpegtran tools.
Stars: ✭ 785 (+468.84%)
Mutual labels:  image, pngquant, performance
Wp Cli Fixtures
Easily generate custom fake data for WordPress
Stars: ✭ 65 (-52.9%)
Mutual labels:  wp-cli, wordpress
Pomodoro
A simple WordPress translation cache
Stars: ✭ 47 (-65.94%)
Mutual labels:  wordpress, performance
Image Optimizer
Simple lossless compression for Elementary OS
Stars: ✭ 52 (-62.32%)
Mutual labels:  image, compression
Wp Vps Build Guide
A verbose build guide for a modern, high-performance WordPress production VPS.
Stars: ✭ 31 (-77.54%)
Mutual labels:  wp-cli, wordpress
Jekyll Cloudinary
Jekyll plugin adding a Liquid tag for Cloudinary, for better responsive images
Stars: ✭ 79 (-42.75%)
Mutual labels:  image, performance
Query Monitor
The Developer Tools Panel for WordPress
Stars: ✭ 1,156 (+737.68%)
Mutual labels:  wordpress, performance
Compress.js
A simple JavaScript based client-side image compression algorithm
Stars: ✭ 86 (-37.68%)
Mutual labels:  image, compression
Hyperdrive
This repository has moved to:
Stars: ✭ 120 (-13.04%)
Mutual labels:  wordpress, performance
Performance Improvements For Woocommerce
Performance tweaks for the front-end and back-end of a store.
Stars: ✭ 46 (-66.67%)
Mutual labels:  wordpress, performance
Vccw
A Vagrant based development environment.
Stars: ✭ 1,012 (+633.33%)
Mutual labels:  wp-cli, wordpress
Wprig
A progressive theme development rig for WordPress.
Stars: ✭ 1,125 (+715.22%)
Mutual labels:  wordpress, performance
Wp Cli Replicator
Replicate production websites from WordPress eXtended RSS (WXR) export files
Stars: ✭ 34 (-75.36%)
Mutual labels:  wp-cli, wordpress
Ext
WP-CLI command which checks the existence of PHP extensions needed to run WordPress.
Stars: ✭ 69 (-50%)
Mutual labels:  wp-cli, wordpress
Wordup Cli
Wordup is a fully integrated development platform for WordPress. Develop plugins and themes locally. Preview in the cloud. Automatic updates in WP.
Stars: ✭ 116 (-15.94%)
Mutual labels:  wp-cli, wordpress
Lerc
Limited Error Raster Compression
Stars: ✭ 126 (-8.7%)
Mutual labels:  image, compression
Awesome Wp Cli
A curated list of packages and resources for WP-CLI, the command-line interface for WordPress.
Stars: ✭ 129 (-6.52%)
Mutual labels:  wp-cli, wordpress
Laravel Image Optimizer
Optimize images in your Laravel app
Stars: ✭ 873 (+532.61%)
Mutual labels:  image, performance

Image Optimize Command

Packagist Packagist PHP from Packagist CircleCI Codecov license Twitter Follow @TangRufus Hire Typist Tech

Easily optimize images using WP CLI

Built with ♥ by Typist Tech


Image Optimize Command is an open source project and completely free to use.

However, the amount of effort needed to maintain and develop new features is not sustainable without proper financial backing. If you have the capability, please consider donating using the links below:

GitHub via Sponsor Sponsor via PayPal More Sponsorship Information


Image Optimize Command is a WP CLI wrapper for spatie/image-optimizer which optimize gif, jpeg, jpg, png, svg, webp images by running them through a chain of various image optimization tools. Read the introductory blog post about why I built it.

Usage

# optimize specific attachments
$ wp image-optimize attachment 123 223 323

# optimize certain number of attachments
$ wp image-optimize batch --limit=20

# restore the full sized images of specific attachments
$ wp image-optimize restore 123 223 323
$ wp media regenerate 123 223 323

# restore all full sized images and drop all meta flags
$ wp image-optimize reset
$ wp media regenerate

# Find and optimize images under a given directory **without backup**
$ wp image-optimize find /path/to/my/directory --extensions=gif,jpeg,jpg,png,svg,webp

# shortcusts for `wp image-optimize find` **without backup**
$ wp image-optimize mu-plugins
$ wp image-optimize plugins
$ wp image-optimize themes
$ wp image-optimize wp-admin
$ wp image-optimize wp-includes

# learn more
$ wp help image-optimize
$ wp help image-optimize <subcommand>

Typist Tech is ready to build your next awesome WordPress site. Hire us!


Requirements

  • PHP v7.2 or later
  • WP-CLI v2.3.0 or greater

Since wp-cli/wp-cli-bundle bundles an older version of symfony/process which incompatible with spatie/image-optimizer, WP-CLI must be installed via composer.

Installation

$ wp package install typisttech/image-optimize-command:@stable

Optimization tools

Under the hood, image-optimize-command invokes spatie/image-optimizer which requires these binaries installed:

Check spatie/image-optimizer's readme for install instructions.

SVGO and cwebp are optional

Note that WordPress doesn't support svg files out of the box. You can omit SVGO. However, if you have enabled WordPress svg support and uploaded svg files to WordPress media library, you must install SVGO. Otherwise, the command will fail.

Same goes for cwebp.

Use Cases

First use

This command optimize both the full sized image(the one you uploaded) and the thumbnails(WordPress auto-resize these images for you).

Chances are the thumbnails are missing or never generated:

  • theme switched after upload
  • plugins activated after upload
  • deleted the images from disk but not updated WordPress' database

Simplest solution is to regenerate thumbnails then optimize:

$ wp media regenerate
$ wp image-optimize batch --limit=9999999

$ wp image-optimize mu-plugins
$ wp image-optimize plugins
$ wp image-optimize themes
$ wp image-optimize wp-admin
$ wp image-optimize wp-includes

After upgrading WordPress core / plugins / themes

$ wp image-optimize mu-plugins
$ wp image-optimize plugins
$ wp image-optimize themes
$ wp image-optimize wp-admin
$ wp image-optimize wp-includes

Restoring the originals

This command backs up the full sized images before optimizing attachments. If you want to restore them:

# optimize
$ wp image-optimize attachment 123

# restore the full sized image
$ wp image-optimize restore 123
# regenerate the thumbnails from the original full sized image
$ wp media regenerate 123

Migrating from image-optimize-command v0.1.x

Starting from v0.2, this command backs up the full sized images before optimizing attachments. To migrate from image-optimize-command v0.1.x:

$ wp image-optimize reset
$ wp media regenerate
$ wp image-optimize batch --limit=9999999

FAQs

What kind of optimization it does?

Mostly applying compression, removing metadata and reducing the number of colors to gif, jpeg, jpg, png, svg, webp images. The package is smart enough pick the right tool for the right image.

Check Freek Van der Herten's article explaining spatie/image-optimizer's sane default configuration.

How to customize the optimization?

use Spatie\ImageOptimizer\OptimizerChain;

add_filter('TypistTech/ImageOptimizeCommand/OptimizerChain', function (OptimizerChain $optimizerChain): OptimizerChain {
    // Option A: Send messages to $optimizerChain.
    $optimizerChain->setTimeout($xxx);
    $optimizerChain->useLogger($yyy);
    $optimizerChain->addOptimizer($zzz);

    // Option B: Make a new $optimizerChain.
    // See: https://github.com/spatie/image-optimizer/blob/master/src/OptimizerChainFactory.php
    $optimizerChain = new OptimizerChain();
    $optimizerChain->addOptimizer($zzz);

    // Finally
    return $optimizerChain;
});

How to skip backups / restorations?

⚠️ The optimzation is lossy. If you skip backing up the original files, there is no way to recover the original files. Proceed with caution.

use TypistTech\ImageOptimizeCommand\Operations\AttachmentImages\Backup;
use TypistTech\ImageOptimizeCommand\Operations\AttachmentImages\Restore;

add_filter('TypistTech/ImageOptimizeCommand/Operations/AttachmentImages/Backup', function (): Backup {
    // TODO: You have to implement a null backup class.
    return $myNullBackupObject;
});

add_filter('TypistTech/ImageOptimizeCommand/Operations/AttachmentImages/Restore', function (): Restore {
    // TODO: You have to implement a null restore class.
    return $myNullRestoreObject;
});

It would be nice to have those 2 null operations in a separate package. Submit pull requests to mention it in this readme if you have implemented it.

Does running wp image-optimize attachment / batch multiple times trigger multiple optimization for the same attachments?

No.

By default, boolean flags (meta fields) are given to attachments after optimization. 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.

Note: The find subcommand and its shortcuts don't create meta flags.

Will the images look different after optimization?

Yes, a little bit. This is lossy optimization. However, you won't notice the difference unless you have a trained eye for that.

See spatie/image-optimizer's readme on binary options used.

Why my GIFs stopped animating?

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...

--- wpbeginner

Luckily for you, Lasse M. Tvedt showed how to stop WordPress from resizing GIFs on StackExchange.

Can I use this on managed hosting?

No, you can't use this on managed hosting such as Kinsta, Flywheel or WP Engine because they prohibit installing the binaries.

If you must use it on managed hosting, hire a developer to add SaaS provider integration:

Do I have to install SVGO or cwebp?

No, if you don't have any svg files in WordPress media library.

Yes, if you have:

Same goes for cwebp.

PHP Fatal error: Allowed memory size of 999999 bytes exhausted (tried to allocate 99 bytes)

This is a common WP CLI issue. See: https://bit.ly/wpclimem

Does it have a limits or quotas?

No, unlike other SaaS alternatives, this package runs on your server without any limitation on file sizes or a monthly quota. Totally free of charge.

Is it for everyone?

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.

Learn more on this article.

Will you add support for older PHP versions?

Never! This plugin will only work on actively supported PHP versions.

Don't use it on end of life or security fixes only PHP versions.

It looks awesome. Where can I find some more goodies like this

Where can I give 5-star reviews?

Thanks! Glad you like it. It's important to let me knows somebody is using this project. Please consider:

Testing

Run the tests:

$ composer test
$ composer style:check

Feedback

Please provide feedback! We want to make this project as useful as possible. Please submit an issue and point out what you do and don't like, or fork the project and send pull requests. No issue is too small.

Security Vulnerabilities

If you discover a security vulnerability within this project, please email us at [email protected]. All security vulnerabilities will be promptly addressed.

Credits

Image Optimize Command is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Special thanks to Freek Van der Herten whose spatie/image-optimizer package makes this project possible.

Full list of contributors can be found here.

License

Image Optimize Command is released under the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].