This code was supposed to add a watermark to the image.
With photoshopped or otherwise edited images it seems to break.
(node:10846) UnhandledPromiseRejectionWarning: Error: Could not find MIME for Buffer <null>
at Jimp.parseBitmap (/Users/maxcampbell/Desktop/Youcon/backend/node_modules/@jimp/core/dist/utils/image-bitmap.js:187:15)
at Jimp.parseBitmap (/Users/maxcampbell/Desktop/Youcon/backend/node_modules/@jimp/core/dist/index.js:431:32)
at new Jimp (/Users/maxcampbell/Desktop/Youcon/backend/node_modules/@jimp/core/dist/index.js:384:13)
at _construct (/Users/maxcampbell/Desktop/Youcon/backend/node_modules/@babel/runtime/helpers/construct.js:19:21)
at /Users/maxcampbell/Desktop/Youcon/backend/node_modules/@jimp/core/dist/index.js:926:32
at new Promise (<anonymous>)
at Function.Jimp.read (/Users/maxcampbell/Desktop/Youcon/backend/node_modules/@jimp/core/dist/index.js:925:10)
at /Users/maxcampbell/Desktop/Youcon/backend/recreate_jimp_error.js:11:18
at FSReqCallback.readFileAfterClose [as oncomplete] (internal/fs/read_file_context.js:63:3)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:10846) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:10846) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
var Jimp = require('Jimp')
const fs = require('fs')
const LOGO_MARGIN_PERCENTAGE = 5;
main = async() => {
const LOGO = "https://upload.wikimedia.org/wikipedia/en/thumb/9/9f/Australian_Defence_Force_Academy_coat_of_arms.svg/1200px-Australian_Defence_Force_Academy_coat_of_arms.svg.png";
fs.readFile('orig.png', 'utf8', async function(err, data) {
if (err) throw err;
const b64 = data.toString('base64')
const [image, logo] = await Promise.all([
Jimp.read(Buffer.from(b64, 'base64')),
Jimp.read(LOGO)
]);
logo.resize(image.bitmap.width / 2, Jimp.AUTO);
const xMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100;
const yMargin = (image.bitmap.width * LOGO_MARGIN_PERCENTAGE) / 100;
const X = image.bitmap.width - logo.bitmap.width - xMargin;
const Y = image.bitmap.height - logo.bitmap.height - yMargin;
let compImage = image.composite(logo, X, Y, [{
mode: Jimp.BLEND_SCREEN,
opacitySource: 0.1,
opacityDest: 1
}]);
compImage.getBase64(Jimp.AUTO, (err, buf) => {
console.log(buf)
})
});
}
main()
Expected Behavior
This code was supposed to add a watermark to the image.
Current Behavior
With photoshopped or otherwise edited images it seems to break.
Failure Information (for bugs)
Error:
Steps to Reproduce
Context