mapslice - Image crop & slice tool
mapslice is a tool to cut images into slices of various zoom levels for use in interactive maps.
Javascript tools for high-performant viewing of huge images are plenty available, yet cropping and slicing images can be a pain with the given tools.
mapslice automatically detects which tile-sizes your input-material supports and creates all possible tiles to be used by a common javascript map tool
like polymaps, kartograph or PanoJS.
Installation
via npm:
$ npm install mapslice
Command line
After installing the latest node, you can use mapslice as a command-line tool by installing it with:
$ npm install mapslice -g
Also make sure that you have GraphicsMagick or ImageMagick installed and available in your command-line!
Once the prerequisites are given, run mapslice using:
$ mapslice -f test.jpg
For more documentation run mapslice without arguments:
$ mapslice
Script usage
const MapSlicer = require('mapslice')
const mapSlicer = new MapSlicer({
file: `myImage.jpg`,
output: `myImage/{z}/{y}/{x}.png`,
outputFolder: './output',
tileSize: 512,
imageMagick: true,
background: '#00000000',
tmp: './temp',
parallelLimit: 3,
minWidth: 200,
skipEmptyTiles: true,
bitdepth: 8,
dither: true,
colors: 128,
gm: require('gm'),
signal: new (require('abort-controller'))().signal
})
mapSlicer.on('start', (files, options) => console.info(`Starting to process ${files} files.`))
mapSlicer.on('imageSize', (width, height) => console.info(`Image size: ${width}x${height}`))
mapSlicer.on('levels', (levels) => { console.info(`Level Data: ${levels}`) })
mapSlicer.on('warning', err => console.warn(err))
mapSlicer.on('progress', (progress, total, current, path) => console.info(`Progress: ${Math.round(progress*100)}%`))
mapSlicer.on('end', () => console.info('Finished processing slices.') )
mapSlicer.start().catch(err => console.error(err))
## Size detection and scaling
To render the image in its fullest glory, mapslice assumes that you want to preserve the original image-quality and chooses input-size as its starting point from which the quality should be reduced. However: If you have a fixed-size map-user-interface then you might want the smallest image quality to fit this user-interface-design in order to assure that its is beautifully visible. To produce tiles that fit this needs you can use the "minWidth" or "minHeight" property which fits the map to have its lowest size matching exactly your required size:
```console
$ mapslice -f test.jpg -w=1000
Will fit the smallest size to be exactly 1000 pixels wide and zoom up from there.
Note
To speed up performance mapslice stores a prescaled version of the each zoom-level in a temorary folder and then just crops off of that. These temporary files can become quite big as they are stored with low compression and high quality in sgi files.
License
MIT