WebPonize



Maintainers
Details

Installs: 7 852 946

Dependents: 57

Suggesters: 2

Security: 0

Stars: 1 889

Webponize.com fetches geolocation, ASN, and hostname information for an IP address Only real eyes see a square below, just trying to distinguish between a human and bots. Click on it to get the geolocation info of your IP address. WebPonize for Mac converts images to Google's WebP; Introduction to WebP. WebP is a new image format by Google. by Shogo Sensui Medium; CSS-Tricks 「WebP is pretty great for serving high quality images better than (pretty much any?) other format right now. But working with them locally isn't great.

Watchers: 57

Forks: 160

Open Issues: 0 Wineskin mac steam.

Requires

  • php: ^7.2|^8.0
  • ext-fileinfo: *
  • psr/log: ^1.0
  • symfony/process: ^4.2|^5.0
Webponize

Requires (Dev)

  • phpunit/phpunit: ^8.0|^9.0
  • symfony/var-dumper: ^4.2|^5.0

Suggests

None

Provides

WebPonize

None

Conflicts

None

This package is auto-updated.

Last update: 2021-03-29 21:44:25 UTC

This package can optimize PNGs, JPGs, SVGs and GIFs by running them through a chain of various image optimization tools. Here's how you can use it:

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 that have been done by this package.

Loving Laravel? Then head over to the Laravel specific integration.

Using WordPress? Then try out the WP CLI command.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

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. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

Optimization tools

The package will use these optimizers if they are present on your system:

Here's how to install all the optimizers on Ubuntu:

And here's how to install the binaries on MacOS (using Homebrew):

And here's how to install the binaries on Fedora/RHEL/CentOS:

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. These options are used:

  • -m85: this will store the image with 85% quality. This setting seems to satisfy Google's Pagespeed 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, a lossy PNG compressor. We set no extra options, their defaults are used. After that we run the image through a second one: Optipng. 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)

SVGs

SVGs will be minified by 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 by Sara Soueidan.

GIFs

GIFs will be optimized by 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. 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)

Usage

This is the default way to use the package:

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 argumentoptimize:

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:

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 Optimizers manually to an OptimizerChain.

Here's an example where we only want optipng and jpegoptim to be used:

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 SpatieImageOptimizerOptimizersOptimizer interface:

If you want to view an example implementation take a look at the existing optimizers shipped with this package.

You can easily add your optimizer by using the addOptimizer method on an OptimizerChain.

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:

A logger is a class that implements PsrLogLoggerInterface. A good logging library that's fully compliant is 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
40 KB

Optimized
16 KB (40%)

WebPonize

jpg

Original: Photoshop 'Save for web' | quality 60, optimized
547 KB

Optimized
525 KB (95%)

credits: Jeff Sheldon, via Unsplash

svg

Original: Illustrator | Web optimized SVG export
26 KB Citrix viewer for mac catalina.

Optimized
20 KB (76%)

webp

Original: WebPonize
528 KB

Optimized
328 KB (89%)

credits: Jeff Sheldon, via Unsplash

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

Contributing

Please see CONTRIBUTING 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), 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.

Credits

This package has been inspired by psliwa/image-optimizer

Emotional support provided by Joke Forment Epson xp 235 driver for mac.

License

The MIT License (MIT). Please see License File for more information.

Webponize Download

WordPress function to delete add-on .webp files with their paired attachments
delete-webp-with-attachment.php

Webponize

<?php
/*
Plugin Name: Delete webp files with image attachments
*/
/*
Make sure to remove .webp files generated by EWWW or manually when their
parent .jpg image and thumbnails are deleted.
This allows you to wipe the EWWW database table, which bloats quickly. If the db is wiped normally, deleting images will leave orphan .webp files.
You can also make .webp files easily with the WebPonize app.
*/
functiondelete_webp_with_img( $attachmentid ) {
// check if we have an image being deleted
if(isset($attachmentid)) {
// get the file path for the image being deleted
$img = get_attached_file($attachmentid);
// get the file path without the .jpg extension
$img_root = preg_replace('/.jp(e)?g|.png|.gif/', ', $img);
// look for .webp files matching the path, including all thumbnails!
$webp_files = glob($img_root . '*.webp');
// do a foreach loop to delete each one
foreach($webp_filesas$webp_file) {
if(file_exists($webp_file)) {
wp_delete_file($webp_file);
}
}
}
}
add_action( 'delete_attachment', 'delete_webp_with_img' );
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment