dev-master
9999999-devFast and lightweight image previews for WordPress
GPLv2
The Requires
- php >=5.3
- composer/installers ~1.0
by Contributors
plugin wordpress images
Fast and lightweight image previews for WordPress
Gaussholder Fast and lightweight image previews, using Gaussian blur. |
|
A Human Made project. Maintained by @rmccue. |
Gaussholder is an image placeholder utility, generating accurate preview images using an amazingly small amount of data., (*1)
, (*2)
That's a 800 byte preview image, for a 109 kilobyte image. 800 bytes still too big? Tune the size to your liking in your configuration., (*3)
Please note: This is still in development, and we're working on getting this production-ready, so things might not be settled yet. In particular, we're still working on tweaking the placeholder size and improving the lazyloading code. Avoid using this in production., (*4)
Gaussholder is inspired by Facebook Engineering's fantastic post on generating tiny preview images. Gaussholder takes the concepts from this post and applies them to the wild world of WordPress., (*5)
In a nutshell, Gaussholder takes a Gaussian blur and applies it to an image to generate a preview image. Gaussian blurs work as a low-pass filter, allowing us to throw away a lot of the data. We then further reduce the amount of data per image by removing the JPEG header and rebuilding it on the client side (this eliminates ~800 bytes from each image)., (*6)
We further reduce the amount of data for some requests by lazyloading images., (*7)
Gaussholder is designed for high-volume sites for seriously advanced users. Do not install this on your regular WP site., (*8)
gaussholder.image_sizes
filter.Your filter should look something like this:, (*9)
add_filter( 'gaussholder.image_sizes', function ( $sizes ) { $sizes['medium'] = 16; $sizes['large'] = 32; $sizes['full'] = 84; return $sizes; } );
The keys are registered image sizes (plus full
for the original size), with the value as the desired blur radius in pixels., (*10)
By default, Gaussholder won't generate any placeholders, and you need to opt-in to using it. Simply filter here, and add the size names for what you want generated., (*11)
Be aware that for every size you add, a placeholder will be generated and stored in the database. If you have a lot of sizes, this will be a lot of data., (*12)
By default Gaussholder is initialized with the DOMContentLoaded
event. Should you need to reinitialize Gaussholder after the page had loaded, this can be achieved with GaussHolder();
., (*13)
The blur radius controls how much blur we use. The image is pre-scaled down by this factor, and this is really the key to how the placeholders work. Increasing radius decreases the required data quadratically: a radius of 2 uses a quarter as much data as the full image; a radius of 8 uses 1/64 the amount of data. (Due to compression, the final result will not follow this scaling.), (*14)
Be careful tuning this, as decreasing the radius too much will cause a huge amount of data in the body; increasing it will end up with not enough data to be an effective placeholder., (*15)
The radius needs to be tuned to each size individually. Facebook uses about 200 bytes of data for their placeholders, but you may want higher quality placeholders. There's no ideal radius, as you simply want to balance having a useful placeholder with the extra time needed to process the data on the page., (*16)
Gaussholder includes a CLI command to help you tune the radius: pick a representative attachment or image file and use wp gaussholder check-size <id_or_image> <radius>
. Adjust the radius until you get to roughly 200B, then check against other attachments to ensure they're in the ballpark., (*17)
Note: changing the radius requires regenerating the placeholder data. Run wp gaussholder process-all --regenerate
after changing radii or adding new sizes., (*18)
Gaussholder is licensed under the GPLv2 or later., (*19)
Gaussholder uses StackBlur, licensed under the MIT license., (*20)
See LICENSE.md for further details., (*21)
Created by Human Made for high volume and large-scale sites., (*22)
Written and maintained by Ryan McCue. Thanks to all our contributors. (Thanks also to fellow humans Matt and Paul for the initial placeholder code.), (*23)
Gaussholder is heavily inspired by Facebook Engineering's post, and would not have been possible without it. In particular, the techniques of downscaling before blurring and extracting the JPEG header are particularly novel, and the key to why Gaussholder exists., (*24)
Interested in joining in on the fun? Join us, and become human!, (*25)
Fast and lightweight image previews for WordPress
GPLv2
plugin wordpress images