svg-rasterizer
Create batched rasterizations of SVG files to other formats suitable for multiple device types.
Given an input of images:
- if
png
, optimize usingpngquaint
- if
svg
, optimize usingsvgo
, then rasterize usingsvgexport
, then optimize if rasters arepng
And copy to a specified dest
directory.
Usage
npm i svg-rasterizer --save
var Rasterizer = var r = <config>r
Configuration
moduleexports = // See debug messages, do not clean up the temporary directory debug: true // svgo options svgOptimizer: plugins: removeViewBox: false // Rasterizations to generate from an svg file // config uses svgexport outputFormats: //Use {{filename}} template to use the original file's filename as a base for the //rasterized file filename: "{{filename}}-2x" format: "png" quality: 100 inputViewbox: null outputSize: "2x" viewboxMode: null styles: null filename: "{{filename}}-3x" format: "png" quality: 100 inputViewbox: null outputSize: "3x" viewboxMode: null styles: null filename: "{{filename}}-jp" format: "jpg" quality: 100 inputViewbox: null outputSize: null viewboxMode: null styles: null // Glob'd directories containing files // Filetypes must be specified input: 'test/mock/data/**/*.svg' 'test/mock/data/**/*.png' // Output directory - uses the directory structure of the input files // when generating output outputDir: 'dist' // Cleans the output dir before running (default is false) cleanOutputDir: false // Directory containing cache metadata for faster build times // set to null to disable caching cacheDir: 'svg-rasterizer-cache'
Grunt Task
A Grunt
task is included, called svg-rasterizer
:
module { grunt grunt grunt
Test
npm run test