lovell / lovell/sharp

Making pixels with different colors transparent when comparing 2 images

Open
#3,754 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
32.7k
Forks
1.4k
Avg merge
1d 14h
Merged PRs (30d)
5

Description

Hi, I got 2 images with are quite similar, but have a different background color. I want to use these different colors to make all those pixels transparent.

So when I have these 2 images:
test-black
test-white

the result would be this:
test-transparent

I got this working with Imagick, but don't even know where to start with Sharp/libvips:

convert test-black.png test-white.png -alpha off \
          \( -clone 0,1 -compose difference -composite -negate \) \
          \( -clone 0,2 +swap -compose divide -composite \) \
          -delete 0,1 +swap -compose Copy_Opacity -composite \
          test-transparent.png

Anybody got some ideas how I could do this in Sharp?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Sharp and libvips documentation for comparing two images and deriving transparency, using the provided ImageMagick command as the behavioral reference. Confirm whether the required operations are already exposed; done means a reproducible Sharp approach that turns differing background pixels transparent while preserving the shared image content.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
computer-graphics
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.