Page 1 of 1

sampling or eyedrop a pixel for transparency

Posted: 2006-03-14T05:28:43-07:00
by shermanfj
greetings:

i'm a brand new user to Image Magick. i actually just downloaded it a few hours ago. from reading the literature, i am impressed. i wish i knew about this stuff 10 years ago. when was it first published? wow!

here is my question:

i have a directory of hundreds of icons that are gifs. all i really know about the images is that i would like to make pixel 1,1 whatever color it is transparent. i'm pretty sure we can choose a certain color to be the transparent color, but i don't know the color. can we sample pixel 1,1 and get it's color and then make it the transparent color for a gif?

is there an -eyedrop function in this stuff? there needs to be one.

thanks folks,
Sherman Jacobsen

http://crt.doce.lsu.edu/sc?ID=20060314

Posted: 2006-03-14T19:22:29-07:00
by anthony
First if you mean the very corner pixel, than that is pixel 0,0

To make all pixels of that color transparent use..

convert image.gif -fill none -draw 'color 0,0 replace' output.gif

To replace only pixels of the same color, connected to that pixel that colro use..

convert image.gif -fill none -draw 'color 0,0 floodfill' output.gif

If you know what color that pixel is (say green) and you want to make any green pixel connected somehow to the edge of the image transparent
ass a green border, floodfill that, then remove that border...

convert image.gif -bordercolor green -border 1x1 \
-fill none -draw 'color 0,0 floodfill' \
-shave 1x1 output.gif

If colors are not exactly the same as the 0,0 pixel, but close (especially for JPEG images) add a -fuzz factor.

See IM examples for...
Replace ing specific colors
http://www.cit.gu.edu.au/~anthony/graph ... or/#opaque
Draw filling and replaceing
http://www.cit.gu.edu.au/~anthony/graph ... raw/#color
GIF transparency handling
http://www.cit.gu.edu.au/~anthony/graph ... rmats/#gif

Enjoy.