sampling or eyedrop a pixel for transparency

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?".
Locked
shermanfj

sampling or eyedrop a pixel for transparency

Post 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

User avatar
anthony
Posts: 8884
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/

Locked