Page 1 of 1

Remove background color????

Posted: 2013-07-12T06:01:12-07:00
by lsintampa
Do you know if it is possible for imagemagick to take a graphic file from a web posting (upload) and determine what the "canvas" and or "page" color is?

Not sure if I'm expressing this correctly, but typically canvas colors are white and unless you save the file as a png with transparent background, the image is on a white block. I'd like to take an image that a user uploads via a web application, determine the canvas color and remove that color (make it transparent).

Is this possible?

Re: Remove background color????

Posted: 2013-07-12T06:41:18-07:00
by snibgo
IM can easily make any given colour transparent, but you have to tell IM which colour that is.

Re: Remove background color????

Posted: 2013-07-16T16:28:31-07:00
by fmw42
If you know you have a reasonably constant background color and know where one pixel of that color may be (perhaps the upper left corner, i.e. 0,0), you can have IM do a fuzzy floodfill at that coordinate and make it some other color or transparent.

see

http://www.imagemagick.org/Usage/draw/#color
http://www.imagemagick.org/Usage/draw/#matte

Re: Remove background color????

Posted: 2013-07-16T21:51:09-07:00
by anthony
Also see Simple background removal
http://www.imagemagick.org/Usage/masking/#floodfill

This will go though many of the issues you will probably face.

Re: Remove background color????

Posted: 2013-07-21T13:42:18-07:00
by lsintampa
If I use this code:

-channel RGBA -bordercolor white -border 1x1 -fill black -floodfill +0+0 white -fuzz 20% -shave 1x1 -resize 176x176 +antialias

that works, I get a nice black background in place of the white

HOWEVER, just changing the -fill black to -fill none (or transparent) does not work and leaves the white background in place

-channel RGBA -bordercolor white -border 1x1 -fill none -floodfill +0+0 white -fuzz 20% -shave 1x1 -resize 176x176 +antialias

I'm at my wits end trying to figure this out. Adding -alpha set to either command will also fail

I'm doing this as a system call from a web application, so I can't really get error codes. All I know is it doesn't floodfill none or transparent - but it will black or any other color for that matter.

Works just as I would want, except I can't get the transparency to floodfill and I don't know why.

Re: Remove background color????

Posted: 2013-07-21T14:52:45-07:00
by fmw42
try

-fill none -draw "matte 0,0 floodfill"

rather than

-fill none -floodfill ...

see
http://www.imagemagick.org/Usage/draw/#matte

Re: Remove background color????

Posted: 2013-07-21T15:27:18-07:00
by lsintampa
fmw42

THANKS - that worked!

Appreciate the quick response!

Re: Remove background color????

Posted: 2014-02-10T06:11:34-07:00
by RyanBram
How to tell ImageMagick to automatically choose the color from top-left pixel as transparent color.
In http://www.imagemagick.org/script/comma ... ransparent , and http://www.imagemagick.org/script/comma ... s.php#fill I don't see such argument

Regards.

Re: Remove background color????

Posted: 2014-02-10T11:12:40-07:00
by fmw42
RyanBram wrote:How to tell ImageMagick to automatically choose the color from top-left pixel as transparent color.
In http://www.imagemagick.org/script/comma ... ransparent , and http://www.imagemagick.org/script/comma ... s.php#fill I don't see such argument

Regards.

Please do not add a new post to an old one. Better to start a new topic. Also identify your version of IM and Platform and explain what you are trying to do and/or provide your command line.

It is not clear what you are trying to do. Please clarify.

In one of the above posts, it was suggested to use

-fill none -draw "matte 0,0 floodfill"

The 0,0 is telling -draw to check the color at 0,0 and floodfill with transparency (color none)

Re: Remove background color????

Posted: 2014-02-10T11:59:45-07:00
by RyanBram
Sorry for my mistake.
I am not aware if reviving old thread even though related to the topic is against forum rules.
I'll be more careful next time.