# Dominant Colors Lazy Loading Contributors: manuelwieser Donate link: https://manu.ninja/ Tags: images, dominant colors, lazy loading, pinterest, javascript, optimization, performance, bandwidth Requires at least: 4.4 Tested up to: 5.0 Stable tag: 0.8.0 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html This plugin allows you to lazy load your images while showing the dominant color of each image as a placeholder – like Pinterest or Google Images. ## Description This plugin allows you to lazy load your images while showing the dominant color of each image as a placeholder – like Pinterest or Google Images. It also enables you to use tiny thumbnails as placeholders. If you want to know how it works read the article [Dominant Colors for Lazy-Loading Images](https://manu.ninja/dominant-colors-for-lazy-loading-images), where I explain the general concept. To ensure the quality of the plugin please let me know if you encounter any issues. I will reply swiftly and fix them as soon as possible! ### Features * The plugin calculates the dominant color of an image upon upload. * All images attached to posts and pages are automatically replaced with placeholders and load as soon as they enter the viewport to save bandwidth. * Galleries added via the default `[gallery]` shortcode are also replaced and loaded as soon as they appear in the viewport. * A custom filter for lazy-loading thumbnails or featured images can be used in templates and themes (`apply_filters( 'dominant_colors', $image, $id )`). * Dominant colors can be calculated for all existing attachments in the plugin settings. * This has already been tested with thousands of images. * Until the calculation is done you can specify a fallback color for your placeholders. * All files that can't be processed are listed during calculation and link to the particular attachment in the media library. * You can choose between GIF and SVG placeholders. * SVG placeholders have the same pixel size and aspect ratio as the original images, instead of being a single square pixel. This way responsive images do not need a wrapper for preserving the original aspect ratio. * GIF placeholders are small and have great browser compatibility. They also enable you to use tiny thumbnails as described on [manu.ninja](https://manu.ninja/dominant-colors-for-lazy-loading-images) for your images. * You can set the resolution of tiny thumbnails to 3×3 pixels (120 bytes), 4×4 pixels (128 bytes) or 5×5 pixels (204 bytes). * The plugin is compatible with [RICG Responsive Images](https://co.wordpress.org/plugins/ricg-responsive-images/), which has been added to WordPress 4.4 as default functionality. ### Demo You can see the plugin live at [http://www.karriere.at/blog/](http://www.karriere.at/blog/). ## Installation 1. Upload `dominant-colors-lazy-loading` folder to the `/wp-content/plugins/` directory. 2. Activate the plugin through the 'Plugins' menu in WordPress. ## Frequently Asked Questions ### Why are no dominant colors and tiny thumbnails calculated? Please make sure that you have installed and activated the `imagick` PHP extension. ### How do I use the custom filter in my themes? ``` $image = get_the_post_thumbnail( $post_id ); $image = apply_filters( 'dominant_colors', $image, get_post_thumbnail_id ( $post_id ) ); echo $image; ``` There is an optional third argument, you can use to specify the format. The available formats are stored as constants in the `Dominant_Colors_Lazy_Loading` class. If you do not specify a format the filter will use the format you have chosen in the plugin settings. * `FORMAT_GIF` will output GIF placeholders. * `FORMAT_SVG` will output SVG placeholders. * `FORMAT_WRAPPED` will output GIF placeholders with wrappers to preserve the aspect ratio of responsive images. ```