Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function encodeImageToStreamNode(image, options) {
// Support MIME type strings
const type = options.type ? options.type.replace('image/', '') : 'jpeg';
const pixels = ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0);
// Note: savePixels returns a stream
return savePixels(pixels, type, options);
}
export const saveImage = async (image, filename, opts) => {
ow(image, ow.object.label('image').nonEmpty)
ow(filename, ow.string.label('filename').nonEmpty)
const pixels = ndarray(image.data, [ image.height, image.width, 4 ])
const parts = filename.split('.')
const format = parts[parts.length - 1]
const stream = savePixels(pixels.transpose(1, 0, 2), format)
return pump(stream, fs.createWriteStream(filename))
}
const zoom = (x, y) => (rgb, value) => {
for (let i = -1; i < 2; i++) {
for (let j = -1; j < 2; j++) {
p.set(x + i, y + j, rgb, value)
}
}
}
points.forEach((point) => {
zoom(from.x, from.y)(point.index, point.rgb)
zoom(target.x, target.y)(point.index, point.rgb)
})
const writableFile = fs.createWriteStream(`lastScreen${screenshotIndex}.png`)
savePixels(p, 'png').pipe(writableFile)
console.log(`[lastScreen${screenshotIndex}.png saved]`)
resolve()
})
})
export function compressImage(image, type = 'png') {
return savePixels(
ndarray(image.data, [image.width, image.height, 4], [4, image.width * 4, 1], 0),
type.replace('image/', '')
);
}
result.data().then(sketchPixels => {
const pixelArray = ndarray(sketchPixels, shape)
streamToPromise(savePixels(pixelArray, 'png')).then(buffer => {
const image = 'data:image/png;base64,' + buffer.toString('base64')
resolve(image)
})
})
})
new Promise(success => {
transitions[tIndex].draw(
progress,
from,
to,
width,
height,
transitionParams[tIndex]
);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, data);
const stream = savePixels(pixels, "png").pipe(outStream);
stream.on("finish", success);
});
//Load input image
var baboon = require("luminance")(require("baboon-image"))
//Allocate storage for result
var result = require("zeros")([512, 512])
//Rotate the image
require("../rotate.js")(result, baboon, Math.PI / 6.0)
//Save the result
require("save-pixels")(result, "png").pipe(process.stdout)
var baboon = require("luminance")(require("baboon-image"))
var x = require("zeros")([256,256])
require("../resample.js")(x, baboon)
require("save-pixels")(x, "png").pipe(process.stdout)
//Generate some shape as a binary voxel image
var x = require("zeros")([256, 256])
x.set(128, 128, 1)
//Distance transform
require("../dt.js")(x)
//Save result
require("save-pixels")(x, "png").pipe(process.stdout)