Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
await formData.default.plans.reduce(async (prev, p) => {
await prev;
const {
name
} = p;
if (req.body[name]) {
try {
const filename = uuid();
const img = await Jimp.read(req.body[name][0].data);
const thumb = await Jimp.read(req.body[name][0].data);
await fs.ensureDir(`${__dirname}/../static/cache/${id}/plans`);
img.scaleToFit(800, Jimp.AUTO);
img.quality(config.qualityThumbPic);
thumb.quality(config.qualityFullPic);
img.composite(watermark, img.bitmap.width - config.watermarkWidth, img.bitmap.height - config.watermarkHeight);
const imgBuffer = await img.getBufferAsync(Jimp.MIME_JPEG);
await fs.writeFile(`${__dirname}/../static/cache/${id}/plans/${filename}.jpg`, imgBuffer);
thumb.cover(config.thumbnailWidth, config.thumbnailHeight, Jimp.HORIZONTAL_ALIGN_CENTER | Jimp.VERTICAL_ALIGN_MIDDLE); // eslint-disable-line no-bitwise
const thumbBuffer = await thumb.getBufferAsync(Jimp.MIME_JPEG);
await fs.writeFile(`${__dirname}/../static/cache/${id}/plans/tn_${filename}.jpg`, thumbBuffer);
plansHash[name] = filename;
} catch (e) {
req.log.error({
ip: req.ip,
path: req.urlData().path,
query: req.urlData().query,
error: e.message
});
rep.code(400)
.send(JSON.stringify({
statusCode: 400,
errors: {
Jimp.read(path.join(screenshot_dir, item), function (err, img) {
if (err) series_cb(null, false); // Not an image, skip it
img.getBuffer(Jimp.MIME_JPEG, function (err, jpg) {
cb(null, jpg);
series_cb(null, true);
});
});
});
execute: async function(image_url) {
try {
//get image then get buffer after contrast
const image = await ofp.friedProcess(image_url, 0.48, 150);
if(image) {
return await image.getBufferAsync(Jimp.MIME_JPEG);
}
} catch(error) {
console.error(error);
}
}
};
if (imageData) {
return imageData;
}
logMessage(`started processing ${imageSrc}`);
const image = await Jimp.read(imageSrc);
const width = image.bitmap.width;
const height = image.bitmap.height;
const resized = image
.scaleToFit(maxPlaceholderWidth, maxPlaceholderHeight)
.quality(placeholderQuality);
const encoded = await resized.getBase64Async(Jimp.MIME_JPEG);
imageData = {
width,
height,
src: encoded,
};
logMessage(`finished processing ${imageSrc}`);
updateCache(imageSrc, imageData);
return imageData;
};
var newData = await new Promise(resolve => {
img.quality(85).getBase64(jimp.MIME_JPEG, function(err, data) {
resolve(data + '"')
})
})
return newData
constructor(className, graph, x, y, settings) {
super(className, graph, x, y, 'Output', OutputProperties, settings);
this.inputs = [
new InputImage(this, 0, 'Input')
];
this.outputs = [];
this.base64 = null;
this.component = null;
this.type = typeof settings.type !== 'undefined' ? settings.type : Jimp.MIME_JPEG;
this.filename = typeof settings.filename !== 'undefined' ? settings.filename : 'NimpDownload';
this.debouncedRenderOutput = debounce(this.renderOutput, 80);
}
image.getBufferAsync(Jimp.MIME_JPEG).then(i => {
resolve('data:'+Jimp.MIME_JPEG+';base64,'+i.toString('base64'));
})
}
execute: async function(text, buffer) {
const template = await Jimp.read(Buffer.from(buffer[0]));
const font = await Jimp.loadFont(Jimp.FONT_SANS_32_BLACK);
buffer = await template.print(font, 350, 25, text, 280);
return await buffer.getBufferAsync(Jimp.MIME_JPEG);
}
};
.then(image => {
image.greyscale().getBuffer(Jimp.MIME_JPEG, onBuffer);
})
.catch(error => {
async function blur(inBuffer) {
const image = await jimp.read(inBuffer);
image.blur(blurRadius);
return image.getBufferAsync(jimp.MIME_JPEG);
}