• Stars
    star
    1,210
  • Rank 38,721 (Top 0.8 %)
  • Language
    JavaScript
  • Created over 7 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Low Quality Image Placeholders (LQIP) for Webpack

lqip-loader: low quality images placeholders for webpack

demo



npm install --save-dev lqip-loader

Generating Base64 & dominant colours palette for a jpeg image imported in your JS bundle:

PS: The large image file will be emitted & only 400byte of Base64 (if set to true in the loader options) will be bundled.

webpack.config.js:

{
  /**
   * OPTION A:
   * default file-loader fallback
   **/
  test: /\.jpe?g$/,
  loaders: [
    {
      loader: 'lqip-loader',
      options: {
        path: '/media', // your image going to be in media folder in the output dir
        name: '[name].[ext]', // you can use [hash].[ext] too if you wish,
        base64: true, // default: true, gives the base64 encoded image
        palette: true // default: false, gives the dominant colours palette
      }
    }
  ]

  /**
   * OPTION B:
   * Chained with your own url-loader or file-loader
   **/
  test: /\.(png|jpe?g)$/,
  loaders: [
    {
      loader: 'lqip-loader',
      options: {
        base64: true,
        palette: false
      }
    },
    {
      loader: 'url-loader',
      options: {
        limit: 8000
      }
    }
  ]
}

your-app-module.js:

import banner from './images/banner.jpg';

console.log(banner.preSrc);
// outputs: "data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhY.... 

// the object will have palette property, array will be sorted from most dominant colour to the least
console.log(banner.palette) // [ '#628792', '#bed4d5', '#5d4340', '#ba454d', '#c5dce4', '#551f24' ]
 
console.log(banner.src) // that's the original image URL to load later!

To save memory and improve GPU performance, browsers (including Chrome started from 61.0.3163.38) will now render a slightly more crisp or pixelated Base64 encoded images.


Older Chrome to the left, Chrome v61 to the right.

If you want the blur to be smooth really bad, here's a fix!

img {
  filter: blur(25px);
}

More history about the issue can be found here and here.

alternatively, you can fill the container with a really cheap colour or gradient from the amazing palette we provide.




Related projects to this would be lqip module for Node as well as lqip-cli.

Thanks to Colin van Eenige for his reviewing and early testing.

MIT - Zouhir Chahoud

More Repositories

1

jarvis

A very intelligent browser based Webpack dashboard
JavaScript
5,438
star
2

preact-habitat

Zero configuration Preact widgets renderer in any host DOM
JavaScript
518
star
3

lqip

Low Quality Image Placeholders (LQIP) Module for Node
JavaScript
433
star
4

preact-phiber

The 3kb alternative to React Fiber with the same API
CSS
30
star
5

lqip-cli

Node CLI for Low Quality Image Placeholders (LQIP)
JavaScript
26
star
6

preact-widgets-boilerplate

A boilerplate for creating portable Preact widgets that can be plugged into any web page!
JavaScript
26
star
7

browser-media-support

Your browser's container formats and codecs support in your pocket.
JavaScript
25
star
8

eslint-config-standard-preact

JavaScript
22
star
9

lqip-loader-example

JavaScript
14
star
10

express-es6-basic-auth-rest-api

JavaScript
13
star
11

matrix-hackernews-client

Preact HN with canvas background rendered off the main thread in a web worker
JavaScript
7
star
12

mojical

JavaScript
6
star
13

mediarecorder-polyfill

JavaScript
4
star
14

pull-to-refresh

JavaScript
4
star
15

blog2

JavaScript
2
star
16

widget-template

JavaScript
2
star
17

devfeeds

JavaScript, Frontend and Engineering Blogs I daily read πŸ“– β˜•
2
star
18

vscode-northem-dark-theme

A north-bluish, dark clean and elegant syntax theme for VS Code
2
star
19

ai-tv

JavaScript
1
star
20

twitter-interactive

CSS
1
star
21

contoso-drive

Responsive dual-screen APIs demo
CSS
1
star
22

preact-widget-scripts

JavaScript
1
star
23

payment-request-demo

Preact \React app demonstrating Web Payments.
JavaScript
1
star
24

http-server-bench

Rust
1
star
25

preact-habitat-youtube

preact-habitat example and demo
JavaScript
1
star