jimp-dev / jimp-dev/jimp

Mask method doesn't give the same result as Gimp

Open
#971 0 comments 0 reactions 0 assignees View on GitHub
bug help wanted
Dominant language
TypeScript
Stars
14.7k
Forks
777
PR merge metrics
No merged PRs in 30d

Description

# Expected Behavior

Jimp's `.mask()` method doesn't give the same output as Gimp. Whether this is a fault of Gimp or Jimp, I'm not certain.

# Current Behavior

The input image has image information on the left, and mask information on the right.

![](https://cdn.discordapp.com/attachments/564536016325574667/787136432057221128/stein_st11.png)

The final result of masking (after inverting the mask) in Gimp (left) vs Jimp (right) (with a black background, to better show transparency discrepancies)

![](https://cdn.discordapp.com/attachments/564536016325574667/787136430060339240/image_masked_bg.png)

## Steps to Reproduce

```javascript
const Jimp = require('jimp');

Jimp.read('input.png')
.then((image) => {
let mask = image
.clone()
.crop(image.bitmap.width / 2, 0, image.bitmap.width / 2, image.bitmap.height)
.invert();
image
.crop(0, 0, image.bitmap.width / 2, image.bitmap.height)
.mask(mask, 0, 0)
.write('output.png');
})
.catch((err) => {
console.log(err);
});
```

**Screenshots**
[Comparison images](https://cdn.discordapp.com/attachments/564536016325574667/787142359859068933/stein_st11.tar.xz)
Image as seen in-game:
![](https://cdn.discordapp.com/attachments/758797346573254766/758802949899157554/latest.png)

## Context

- Jimp Version: `0.16.2-canary.969.1115.0`
- Operating System: `Windows 10 LTSC 1809 Build 17763.1577`
- Node version: `v12.18.0`

Extra note: Found and read issue #949, and I believed my issue to be different. Please close this issue if you think otherwise.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.