https://github.com/redsift/rollup-plugin-imagedata
Import image data and metadata into a rollup JavaScript bundle
https://github.com/redsift/rollup-plugin-imagedata
Last synced: 6 months ago
JSON representation
Import image data and metadata into a rollup JavaScript bundle
- Host: GitHub
- URL: https://github.com/redsift/rollup-plugin-imagedata
- Owner: redsift
- License: mit
- Created: 2016-08-05T17:06:24.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-09T16:47:34.000Z (almost 10 years ago)
- Last Synced: 2025-02-11T09:47:23.940Z (over 1 year ago)
- Language: JavaScript
- Size: 15.6 KB
- Stars: 1
- Watchers: 19
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# rollup-plugin-imagedata
[](https://circleci.com/gh/redsift/rollup-plugin-imagedata)
[](https://www.npmjs.com/package/@redsift/rollup-plugin-imagedata)
[](https://raw.githubusercontent.com/redsift/rollup-plugin-imagedata/master/LICENSE)
Import metadata and base64 encoded image content from JPG, PNG, GIF, WEBP and SVG.
## Installation
```bash
$ npm install --save-dev "@redsift/rollup-plugin-imagedata"
```
## Building via ES6 modules
```js
// 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()
```js
// gulpfile.js
var imagedata = require('@redsift/rollup-plugin-imagedata')
gulp.task('task', () => {
return rollup({
...
plugins: [
imagedata.image(),
...
]
})
.pipe(source('index.js', 'src'))
```
## Usage
```js
// 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().
```js
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.
```bash
$ 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](https://github.com/rollup/rollup-plugin-image).