How to make color from top left pixel transparent?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to make color from top left pixel transparent?

Post by fmw42 »

Do you want every pixel with that same color to be transparent or only the top left pixel to be transparent?

The former can be done either in two command lines:

color=`convert logo: -format "%[pixel:p{0,0}]" info:`
convert logo: -transparent $color logo_tmp.png

or combined into one command line

convert logo: -transparent $(echo `convert logo: -format "%[pixel:p{0,0}]" info:`) logo_tmp.png


see fx escapes:
http://www.imagemagick.org/Usage/transform/#fx_escapes


The latter can be done as follows:

convert rose: -alpha on -channel RGBA -fx "i==0&&j==0?none:u" rose_tmp.png
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to make color from top left pixel transparent?

Post by el_supremo »

This will also do it:

Code: Select all

convert input.png -alpha on -fill none -draw 'color 0,0 replace' output.png
This will replace those pixels which are exactly the same colour as the one at (0,0).
If you also want it to match colours close to the one at (0,0), you can also add a fuzz factor, e.g. -fuzz 5% Put it before the -draw option.

Pete
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to make color from top left pixel transparent?

Post by fmw42 »

el_supremo:

your method is clearly superior to mine.
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: How to make color from top left pixel transparent?

Post by el_supremo »

Hi Fred:
your method is clearly superior to mine.
I keep a file of "IM tidbits" that I have gleaned from this forum and the email reflector. I can't take the credit for it but unfortunately I don't remember who to give the credit to.

Best Wishes
Pete
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to make color from top left pixel transparent?

Post by fmw42 »

Hi Pete,

I, too, have been keeping an IM tidbits file from tips on the forum, from Anthony Thyssen and from things with which I have experimented. I keep my eye on the forums to learn new techniques and for challenges to try and for script ideas. I have added your method into my iM tidbits file.

Fred
Post Reply