@redsift/rollup-plugin-imagedata
v1.0.1
Published
Import image data and metadata into a rollup JavaScript bundle.
Downloads
3
Readme
rollup-plugin-imagedata
Import metadata and base64 encoded image content from JPG, PNG, GIF, WEBP and SVG.
Installation
$ npm install --save-dev "@redsift/rollup-plugin-imagedata"
Building via ES6 modules
// rollup.config.js
import image from '@redsift/rollup-plugin-imagedata';
export default {
entry: './index.js',
dest: 'distribution/my-lib.js',
plugins: [
image()
]
};
Building via require()
// gulpfile.js
var imagedata = require('@redsift/rollup-plugin-imagedata')
gulp.task('task', () => {
return rollup({
...
plugins: [
imagedata.image(),
...
]
})
.pipe(source('index.js', 'src'))
Usage
// use.js
import { width, height, base64 } from './tests/test.png';
console.log(`My image is ${width} pixels wide`);
...
Note that base64 makes the images 33% larger than the size on disk.
Tree shaking via rollup will ensure large payloads such as the base64 string will be stripped from the bundle if not imported or used by your code.
Options
You may pass a few options to image().
image({
include: [ ... ], // files to include
exclude:[ ... ], // files to exclude
patch: false, // attempt to fix up non compliant assets e.g. SVG files with no XML headers
ignoreParsingErrors: true // Warn but do not fail if files cannot be parsed as images.
// In this case metadata will be missing
});
ImageMagick
This plugin relies on having ImageMagick installed and in the path as this tool is used to extract metadata from the images. If you wish to use WebP, ensure your binary has support for the format. You can verify your binary by inspecting the built in delegates.
$ convert -version
Version: ImageMagick 6.9.3-7 Q16 x86_64 2016-04-13 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2016 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jp2 jpeg lcms ltdl lzma png tiff webp xml zlib
Tested on OS-X with ImageMagick-6.9.3-7
OS-X & Homebrew
To reinstall imagemagick with WebP support brew reinstall imagemagick --with-webp
Acknowledgements
This plugin is derived from rollup-plugin-image.