The blit function takes optional arguments srcx, srcy, srcw, srch to specify a region of the source image to blit. For example, if the source image is a 100w x 100h square and the destination is a 50w x 100h rectangle, it should be possible to blit the left half of the source image into the destination with dest.blit(src, 0, 0, 0, 0, 50, 100), or the right half with dest.blit(src, 0, 0, 50, 0, 50, 100).
This worked as expected in Jimp 0.2.28, but it no longer works in Jimp 0.4.0 (I haven't tested any other versions).
Blitting the left half of the source image (with srcx = 0) works as expected, but blitting the right half (with srcx > 0) doesn't affect the desination image at all. The problem seems to involve the following check at line 68 of plugin-blit/dist/index.js:
if (x + sx >= 0 && y + sy >= 0 && maxw - x - sx > 0 && maxh - y - sy > 0)
This check causes all pixels to be skipped when blitting the right half of the source image. I'm not sure whether the problem is the check itself, or the values of sx and sy that are being passed to the scanQuiet() callback.
Thank you for this fantastic project!
Hmm this seems to work the same in both for me
const dest = await Jimp.read('./exampleImages/canyons.png');
const src = await Jimp.read('./exampleImages/player.png');
dest
.blit(
src,
src.getWidth() / 2,
0,
src.getWidth() / 2,
0,
src.getWidth() / 2,
src.getHeight()
)
.write('test.png', console.log);
If you can provide me images and an example that'd be awesome!
@akwizgran
I'm going to add a +1 to this. My app had been silently producing blank images since 0.3.x, and nobody noticed, since the function was seldom-used. I was doing a partial re-write and started tearing my hair out over why it was spitting out blank images.
Reverting to 0.2.28 fixed things.
Heres a silly fiddle demonstrating the problem: https://jsfiddle.net/t3rminus/gbzne7v3/25/
It loads 3 images:
https://www.k3vin.net/fuzz/cat_butt.png
https://www.k3vin.net/fuzz/cat_head.png
https://www.k3vin.net/fuzz/cat_fuzz.png
Then blits them together, selecting a random horizontal slice of the originals, and repeating the "fuzz" middle section depending on how "long" you want your cat to be.
@t3rminus that was super useful! I basically added your code as test cases. The cat example made me laugh. I've opened #613. Once merged I'll put a release together.
Released in v0.5.0
Seems to be working now https://jsfiddle.net/n7rd8by3/ 馃帀
Most helpful comment
@t3rminus that was super useful! I basically added your code as test cases. The cat example made me laugh. I've opened #613. Once merged I'll put a release together.