Place background color in multiple images in an instance.

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
IamBGthegreat
Posts: 7
Joined: 2016-09-25T10:33:52-07:00
Authentication code: 1151

Place background color in multiple images in an instance.

Post by IamBGthegreat »

http://graphicdesign.stackexchange.com/ ... ansparency

Similar to that link, but I want to put background color in hudreds of PNG's. Tried many solutions, but still, doesn't work.

what am I going to do? please help.

P.S. I'm not really much of an internet user so sorry if I did the posting wrong in this forums.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Place background color in multiple images in an instance.

Post by snibgo »

There are two parts to your question.

(1). What do you mean by "I want to put background color in" an image? Perhaps they have transparency but you want to put a colour there, eg:

Code: Select all

convert in.png -background blue -layers flatten out.png
(2). You want to do this for hundreds of PNGs. Then mogrify might do what you want, but I would write a shell script. See the link you gave for a bash script.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Place background color in multiple images in an instance.

Post by fmw42 »

Perhaps you should post an example image to some place such as dropbox.com and put the URL here. Then tell us what you want changed.

Also please always provide your IM version and platform as syntax may differ, especially for scripting
IamBGthegreat
Posts: 7
Joined: 2016-09-25T10:33:52-07:00
Authentication code: 1151

Re: Place background color in multiple images in an instance.

Post by IamBGthegreat »

Thanks for the reply guys. It was late night the time I post it and I couldn't state really well.

I download PNGs in this website http://infinitymugenteam.com/FrameSprites_MVC2.htm and I'm going to animate this PNG sequences in After Effects. I download the character specifically Jin

Problem is when I try to import them in my first attempt without using ImageMagick, there's a pink background.

When I try to use this method

Code: Select all

FOR %G IN (*.png) DO convert %G -transparent #FF00FF batch\%G
to remove the pink background, there's still a pink background in After Effects when I try to import it eventhough its already gone.

Then another alternative, is to color all the PNGs green so that I'm just going to use chroma keys.

Here is the output which didn't worked really well in After Effects (Same in Photoshop when I try to import it still has a pink background)

Raw file that I downloaded:
http://imgur.com/a/9HSJ0

Using the "FOR %G IN (*.png) DO convert" method:
http://imgur.com/a/prngU


Also, snibgo, I tried using the code that you've mentioned

Code: Select all

convert in.png -background blue -layers flatten out.png
.
http://imgur.com/a/98wMy


None of them worked in After Effects, I just need them to be transparent, if not, to color them with green background.

P.S. I'm running on a Windows platform.

EDIT: Just some additional information, Tried this

Code: Select all

convert image.png -fill white -opaque none output.png
and it works. Can you guys help me how to color the background green multiple images?

Using the code:
http://imgur.com/a/gClnA
Last edited by IamBGthegreat on 2016-09-25T16:16:41-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Place background color in multiple images in an instance.

Post by fmw42 »

Those files do not decompress on my Mac.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Place background color in multiple images in an instance.

Post by fmw42 »

The one file you provided separately has no transparency. So you need to change pink to some other color. That may not work well since that will likely result in aliasing near the edge of the figure.

try this

Code: Select all

convert uFzdUpG.png -fuzz 10% -fill green1 -opaque "#F707F7" result.png
The fuzz percent is to allow near "pink" colors (#F707F7) to be considered the same as the "pink" color. You can lower that percent as long as it changes pink to green. If you make it too big, you will change colors of your object.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Place background color in multiple images in an instance.

Post by snibgo »

Colours near #f0f are called magenta, not pink.

When you look at the result in other programs such as Gimp, is the magenta still there? If not, then the problem is in your use of After Effects. Perhaps you need to tell it to regard the alpha channel, or something.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Place background color in multiple images in an instance.

Post by fmw42 »

If you have a lot of files with the same background color and want to change them all to one new color such as pink to green, then you can use mogrify to process all the files in a folder. You should create a new empty folder to hold all the new ones. Say all your files are in folder test1 and you create a new folder called test2. The do the following


Unix syntax.

Code: Select all

cd path2/test1
mogrify -path path2/test2 -format png -fuzz 10% -fill green1 -opaque "#F707F7" *.png
Use windows syntax to change directories in place of cd if there is no cd. The mogrify command should still be the same syntax except for your path2 to get to the directories test1 and test2
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Place background color in multiple images in an instance.

Post by fmw42 »

Note that green1 or lime is the equivalent name for #00FF00 or rgb(0,255,0). You can use any of these ways to specify colors in IM.

see http://www.imagemagick.org/script/color.php
IamBGthegreat
Posts: 7
Joined: 2016-09-25T10:33:52-07:00
Authentication code: 1151

Re: Place background color in multiple images in an instance.

Post by IamBGthegreat »

snibgo wrote:Colours near #f0f are called magenta, not pink.

When you look at the result in other programs such as Gimp, is the magenta still there? If not, then the problem is in your use of After Effects. Perhaps you need to tell it to regard the alpha channel, or something.

Yeah, just recently knew After Effects doesn't recognized palette based transparency images so the background is always magenta. So my remaining solution is to just color the background green and just use chroma key.
IamBGthegreat
Posts: 7
Joined: 2016-09-25T10:33:52-07:00
Authentication code: 1151

Re: Place background color in multiple images in an instance.

Post by IamBGthegreat »

fmw42 wrote:If you have a lot of files with the same background color and want to change them all to one new color such as pink to green, then you can use mogrify to process all the files in a folder. You should create a new empty folder to hold all the new ones. Say all your files are in folder test1 and you create a new folder called test2. The do the following


Unix syntax.

Code: Select all

cd path2/test1
mogrify -path path2/test2 -format png -fuzz 10% -fill green1 -opaque "#F707F7" *.png
Use windows syntax to change directories in place of cd if there is no cd. The mogrify command should still be the same syntax except for your path2 to get to the directories test1 and test2

THANKS IT WORKS!!! I tried this code:

Code: Select all

mogrify -path Jin -format png -fuzz 10% -fill green1 -opaque "#F707F7" *.png
Thanks you so much my friends..
Post Reply