mosaic-image-stream
Streaming mosaic of multiple images into a single image
Take a 2-D array of input pixel-streams
and mosaic them together into a single image. Everything is streams, so you can theoretically mosaic thousands of images into a megapixel image without much memory usage.
Table of Contents
Install
npm i mosaic-image-stream
Usage
See examples.
Mosaic local file streams:
var fs = var path = var PNGDecoder = var PNGEncoder = var Mosaic = var baseName = path var streams = fs fs fs fs fs fs fs fs fs
The giant wallmap of the Middle East you've always wanted (17,000px x 17,000px):
var fs = var path = var request = var JPGDecoder = var JPGEncoder = var tilebelt = var MAPBOX_TOKEN = 'pk.eyJ1IjoiZ21hY2xlbm5hbiIsImEiOiJSaWVtd2lRIn0.ASYMZE2HhwkAw4Vt7SavEg'var urlBase = 'https://api.mapbox.com/v4/mapbox.streets/' var Mosaic = var zoom = 8var tl = tilebeltvar br = tilebelt var size = br0 - tl0 + 1 br1 - tl1 + 1var factories = Arraysize0
Mosaic a whole bunch of images from Flickr:
var fs = var path = var request = var JPEGDecoder = var JPEGEncoder = var Mosaic = var reqUrl = 'https://api.flickr.com/services/rest/?' + 'method=flickr.photos.search&' + 'api_key=ea621d507593aa247dcaa792268b93d7&' + 'tags=portrait&' + 'sort=interestingness-desc&' + 'media=photos&' + 'extras=url_q&' + 'format=json&' + 'nojsoncallback=1&' + 'per_page=500' // One of the images Flickr returns does not have a height of 150px, even though the Flickr API thinks it doesvar badUrl = 'https://farm2.staticflickr.com/1554/24516806801_084046c4dc_q.jpg' var size = 15 15
Input streams must be pixel-streams
. If you want to stream raw image data, stream it through a pixel-stream
constructed with your image width, height and color space:
myRawImageStream
API
var Mosaic =
Mosaic(streams, height)
Where:
streams
- a 2-d array of input stream, columns, then rows: e.g.streams = [[row1col1, row2col2], [row1col2, row2col2]]
height
- the total height of the input streams (width can be calculated on the fly from input images)
All input streams must have the same dimensions and color space - the output stream will throw an error if they differ, or if the total height of the input streams does not match the height specified.
Returns a pixel-stream
.
Contribute
PRs accepted.
Small note: If editing the Readme, please conform to the standard-readme specification.
License
MIT © Gregor MacLennan / Digital Democracy