imageMap.forEach((frame, index) => { const tempImage = new Jimp(0, 0); tempImage.bitmap = new BitmapImage(frame.bitmap).bitmap; largeFrame.composite(tempImage, getPixel(index), 0); });
Promise.all(results.map(async result => { if (result.animated) { const { body } = await get(result.url); return prepareFrames(result, body); } const image = await read(result.url); return prepareFrames(result, new GifFrame(new BitmapImage(image.bitmap))); }))
dataURIPromises.push( jimp .read(facesDataList[i].image_url) .then((image) => // resize the image to be thumbnail size image.resize(45, 45).getBase64Async(jimp.MIME_PNG) ) // promise.all rejects if one of the promises in the array gets rejected, // without considering whether or not the other promises have resolved. // This is to make sure Promise.all continues evluating all promises inspite some rejections. .catch(() => undefined) );
image.getBuffer(MIME_PNG, (error, img) => { if (error) reject(error); else resolve(img); })
async function loadImage (path) { let img = await Jimp.read(path) img.resize(400, 300) const p = [] img.scan(0, 0, img.bitmap.width, img.bitmap.height, function (x, y, idx) { p.push(this.bitmap.data[idx + 0]) p.push(this.bitmap.data[idx + 1]) p.push(this.bitmap.data[idx + 2]) }) return tf.tensor3d(p, [400, 300, 3]).reshape([1, 400, 300, 3]).sub(MEANS) }
frames.map(async frame => { const image = new Jimp(frame.bitmap.width, frame.bitmap.height); const bImage = new BitmapImage(frame); image.bitmap = bImage.bitmap; image.resize(result.type === "unicode" ? 72 : 128, AUTO); return new GifFrame(bImage); });
function saveImage (path, tensor) { let newTensor = tensor.add(MEANS).reshape([400, 300, 3]) const newTensorArray = Array.from(newTensor.dataSync()) let i = 0 return new Promise(function (resolve, reject) { // eslint-disable-next-line no-new new Jimp(400, 300, function (err, image) { if (err) return reject(err) image.scan(0, 0, image.bitmap.width, image.bitmap.height, function (x, y, idx) { this.bitmap.data[idx + 0] = newTensorArray[i++] this.bitmap.data[idx + 1] = newTensorArray[i++] this.bitmap.data[idx + 2] = newTensorArray[i++] this.bitmap.data[idx + 3] = 255 }) image.write(path) return resolve(null) }) }) }
async compareImages (params) { let baseFilePath = params.baseFilePath let testFilePath = params.testFilePath let diffFilePath = params.diffFilePath let baseImg = await Jimp.read(baseFilePath) let testImg = await Jimp.read(testFilePath) let diff = Jimp.diff(baseImg, testImg) return new Promise(resolve => { const data = { data: { misMatchPercentage: diff.percent, isSameDimensions: baseImg.bitmap.width === testImg.bitmap.width && baseImg.bitmap.height === testImg.bitmap.height, passThreshold: diff.percent <= this.options.mismatchThreshold } } if (!diff.percent) { return resolve(data) } diff.image.write(diffFilePath, () => { resolve(data) }) }) }
compositor: 'jimp' }, function (err) { Jimp.read(tmp + '/sprite.png', function (err, lenna) { if (err) throw err; lenna.quality(parseInt(85))
console.log('Before Data width', image.bitmap.width); console.log('Before Data height', image.bitmap.height); this.rotate(90) console.log('After flip Data width', image.bitmap.width); console.log('Data height', image.bitmap.height); .greyscale(); console.log('Data len', image.bitmap.data.length); console.log('Data width', image.bitmap.width); console.log('Data height', image.bitmap.height);
frames.map(async frame => { const image = new Jimp(frame.bitmap.width, frame.bitmap.height); const bImage = new BitmapImage(frame); image.bitmap = bImage.bitmap; image.resize(128, AUTO); return new GifFrame(bImage); });
tempImage.getBuffer(MIME_PNG, (error, buffer) => error ? reject(error) : resolve(buffer))