This plugin automatically compresses and scales down overly large images on upload.
On upload:
- the full-size image will be checked for min/max size constraints and scale if necessary
- It will then be optimized for filesize
- After thumbs are generated, a WebP copy of each size is created with the same filename +
.webpsuffix. - If enabled, all
<img>tags on your sites frontend will be replaced with<picture>tags that use the WebP file with original image as a fallback for browsers without WebP support.
git cloneto /wp-content/plugins/flyn-image-optimizercomposer install- For Ubuntu:
apt-get update && apt-get install advancecomp pngcrush gifsicle jpegoptim imagemagick pngnq optipng pngquant - For OSX:
brew install advancecomp pngcrush gifsicle jpegoptim imagemagick pngnq optipng pngquant svgo wp-cli - Restart
apacheandphp-fpmservices wp-cliis required for batch operations
For maximum performance, this plugins functionality is changed through filters rather than an admin page. See the Filters section below for details.
WebP generation is enabled by default but automatic replacing on frontend images isn't. This is because you probably don't have WebP files generated for all your existing images yet.
Run the CLI command wp flynio regenerate --scale --optimize before enabling this functionality.
By default uploaded images are scaled to a minimum of 100x100 or maximum of 3840x3840. This can be changed with:
add_filter('flynio-limit-dimensions', function ($dimensions) {
return [
[150, 150], // minimum x/y dimensions
[1920, 1080], // maximum x/y dimensions
];
});By default bitmaps and tiffs are converted to jpeg on upload. This can be overridden with:
add_filter('flynio-mimes-to-convert', function ($mimes) {
return ['image/bmp', 'image/tif', 'image/tiff'];
});If using homebrew you'll likely want to overwrite the image optimizer's default filepaths like so:
add_filter('flynio-optimizer-options', function ($options) {
return array_merge($options, [
'jpegtran_bin' => '/usr/local/bin/jpegtran',
'jpegoptim_bin' => '/usr/local/bin/jpegoptim',
'pngcrush_bin' => '/usr/local/bin/pngcrush',
'optipng_bin' => '/usr/local/bin/optipng',
'pngquant_bin' => '/usr/local/bin/pngquant',
]);
});By default NullLogger is used by the image optimizer. Set a custom logger with the following:
class StdoutLogger extends \Psr\Log\AbstractLogger
{
public function log($level, $message, array $context = [])
{
if (!empty($context['exception'])) {
echo $context['exception']->getMessage();
} else {
echo $message;
}
echo "<br/>\n";
}
}
add_filter('flynio-optimizer-logger', function ($logger) {
return new StdoutLogger();
});add_filter('flynio-generate-webp-images', '__return_false');add_filter('flynio-use-webp-images', '__return_true');