All Projects β†’ Calvin-LL β†’ webpack-image-placeholder-loader

Calvin-LL / webpack-image-placeholder-loader

Licence: MIT License
Generate a solid color image as placeholder

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to webpack-image-placeholder-loader

React Shimmer
🌠 Async loading, performant Image component for React.js
Stars: ✭ 990 (+4025%)
Mutual labels:  placeholder, loader
React Image Appear
ReactJS component to make images appear with transition as they load.
Stars: ✭ 264 (+1000%)
Mutual labels:  placeholder, loader
Skeleton Elements
Skeleton elements - UI for improved perceived performance
Stars: ✭ 27 (+12.5%)
Mutual labels:  placeholder, loader
Ng Image Appear
AngularJS Module to make images appear with transition as they load.
Stars: ✭ 120 (+400%)
Mutual labels:  placeholder, loader
React Content Loader
βšͺ SVG-Powered component to easily create skeleton loadings.
Stars: ✭ 11,830 (+49191.67%)
Mutual labels:  placeholder, loader
Ocskeleton
[OCSkeleton] - Make your loading view a little difference.
Stars: ✭ 184 (+666.67%)
Mutual labels:  placeholder, loader
React Native Loading Placeholder
React Native Loading Placeholder
Stars: ✭ 176 (+633.33%)
Mutual labels:  placeholder, loader
Rhplaceholder
Show pleasant loading view for your users 😍
Stars: ✭ 238 (+891.67%)
Mutual labels:  placeholder, loader
LoadersPack-Android
Android LoadersPack - a replacement of default android material progressbar with different loaders
Stars: ✭ 119 (+395.83%)
Mutual labels:  loader
dts-css-modules-loader
A small Webpack loader to generate typings for your CSS-Modules
Stars: ✭ 44 (+83.33%)
Mutual labels:  loader
nunjucks-loader
Webpack loader for Nunjucks templates
Stars: ✭ 20 (-16.67%)
Mutual labels:  loader
architectury-api
An intermediary api aimed at easing development of multiplatform mods.
Stars: ✭ 139 (+479.17%)
Mutual labels:  loader
es2postgres
ElasticSearch to PostgreSQL loader
Stars: ✭ 18 (-25%)
Mutual labels:  loader
faker
A kotlin extension to load images asynchronously on android
Stars: ✭ 58 (+141.67%)
Mutual labels:  loader
python-yamlordereddictloader
(DEPRECATED) YAML loader and dumper for PyYAML allowing to keep keys order.
Stars: ✭ 25 (+4.17%)
Mutual labels:  loader
memory-module-loader
An implementation of a Windows loader that can load dynamic-linked libraries (DLLs) directly from memory
Stars: ✭ 111 (+362.5%)
Mutual labels:  loader
promise
Common interface for simple asynchronous placeholders.
Stars: ✭ 66 (+175%)
Mutual labels:  placeholder
dynamic-import-assets
Dynamic Imports for JavaScript and CSS.
Stars: ✭ 20 (-16.67%)
Mutual labels:  loader
hzk-pixel-font
δΈ­ζ–‡εƒη΄ ε­—δ½“οΌŒ12 ε’Œ 16 像素。
Stars: ✭ 14 (-41.67%)
Mutual labels:  pixel
phaser-webpack-loader
Asset loader for Phaser + Webpack.
Stars: ✭ 85 (+254.17%)
Mutual labels:  loader

webpack-image-placeholder-loader

npm License: MIT

This loader generates a color or solid color image or blurred image from a given image for use as a placeholder.

Under the hood this package uses fast-average-color. See fast-average-color for examples of colors derived from images.

Supports JPEG, PNG, WebP, TIFF, GIF and SVG images.

Examples

Blurred Placeholder Solid Color Placeholder
Blurred Background Solid Color Background

React

Vue

React example with other related loaders

Vue example with other related loaders

Install

Install with npm:

npm install --save-dev webpack-image-placeholder-loader

Install with yarn:

yarn add --dev webpack-image-placeholder-loader

Usage

Step 1

webpack.config.js
module.exports = {
  // ...
  module: {
    rules: [
      // ...
      {
        test: /\.(png|jpe?g|svg|gif|webp|tiff?)$/i,
        oneOf: [
          {
            // if the import url looks like "some.png?placeholder..."
            resourceQuery: /placeholder/,
            use: {
              loader: "webpack-image-placeholder-loader",
              options: {
                format: "hex",
              },
            },
          },
          {
            // if no previous resourceQuery match
            use: "file-loader",
          },
        ],
      },
    ],
  },
};

Step 2

Use in code
import placeholderUrl from "./some_pic.png?placeholder";

To override options for one import, you can use queries

import placeholderUrl from "./some_pic.png?placeholder&size=original";

Other usage

With default options:

import placeholderUrl from "!!webpack-image-placeholder-loader!./some_pic.png";

With specified options:

import placeholderUrl from "!!webpack-image-placeholder-loader!./some_pic.png?format=base64&size=1&color=sqrt&backgroundColor=white";

Options

Name Type Default Description
format "base64", "blurred-svg", "hex", "rgb", or "array" "base64" The format of the output.
size number or "original" 1 The size of the output image if format is "base64", no effect if the format is anything else.
blurQuality number 1 The quality of blur image if format is "blurred-svg", no effect if the format is anything else. Possible values from 0 (not including 0) to 100 (including 100).
color string|object "sqrt" An algorithm ("simple", "sqrt" or "dominant") to generate a color from a given image, or a color string or color object to use in generating the output image.
backgroundColor string|object "#FFF" The background color to use if the given image has transparency.
esModule boolean true Whether the export is in ES modules syntax or CommonJS modules syntax.

format

With

import placeholderUrl from "./some_pic.png?placeholder";
  • format: "base64": placeholderUrl === "data:image/png;base64,iVBORw0KG..."
  • format: "blurred-svg": placeholderUrl === "data:image/svg+xml;charset=utf-8,%3Csvg xmlns=..."
  • format: "hex": placeholderUrl === "#6b7548"
  • format: "rgb": placeholderUrl === "rgb(107, 117, 72)"
  • format: "array": placeholderUrl === [107, 117, 72]"

size

size will only take effect if format: "base64". When size is a number, the output image will be a square of the given number of pixels. When size: "original", the output image will be the size of the original image.

color

color can be an algorithm ("simple", "sqrt" or "dominant") to generate a color from a given image (see examples in algorithm), or a color string or color object to use in generating the output image.

A color string or color object is any valid colors accepted by TinyColor.

For example:

{
  color: "white",
  format: "base64"
}

will output a white pixel.

{
  color: "white",
  format: "hex"
}

will output #FFFFFF

backgroundColor

If an image has transparency, backgroundColor will be used as the background color. By default backgroundColor is white.

blurQuality

When used with "blurred-svg", the image is first shunk by this percentage, stretched, then blurred.

1 is 1/100 of the original quality. 100 is the original quality (DO NOT recommand using 100). Can be decimal numbers too, 0.1 would be 1/1000 of the original quality. The lower the value, the more blurry the image will be, and the smaller the size.

esModule

Whether the export is in ES modules syntax or CommonJS modules syntax. If you don't know what it is or whether or not you need it, leave is as default.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].