Issue with photoshopped and edited images
- Dominant language
- TypeScript
- Stars
- 14.7k
- Forks
- 777
- PR merge metrics
- No merged PRs in 30d
Description
# 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:
```
(node:10846) UnhandledPromiseRejectionWarning: Error: Could not find MIME for Buffer
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 ()
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.
```
## Steps to Reproduce
1. Create a new file test.js
2. Put the code below in it.
3. Put any photoshopped file in the same folder as test.js and name the image 'orig.png'
```
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()
```
## Context
- Jimp Version: 0.16.1
- Operating System: macOS Catalina 10.15.4
- Node version: 14.5.0
Contributor guide
Research direction
Start with the reproduction in recreate_jimp_error.js and the Jimp.read call shown in the issue. Run it with the supplied photoshopped image and compare the result with an unedited image. Done means the image is read successfully and the watermark operation produces the expected output without the MIME error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100