Page 1 of 1

[Solved]Alpha Background using another image. Multi-files.

Posted: 2014-02-15T16:15:47-07:00
by wmichaelv
I would like to do the following:

Before[raw]:

Image ++++++++++++++++ Image

character0*.png [using *, intended to be multiple files] + back.png

After [result]:

Image

character0*.png [using *, intended to be multiple files] (done via photoshop)

What I need to do:
1. [raw]
2. convert character0*.png from 'indexed color' into 'RGB color'
3. ???
4. [result]

This is my -version

Code: Select all

c:\Users\mini\Desktop\utsuho>convert -version
Version: ImageMagick 6.8.8-5 Q16 x64 2014-02-08 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo freetype jbig jng jp2 jpeg lcms lqr pangocairo png ps rsv
g tiff webp xml zlib
This is my -list configure

Code: Select all

C:\>convert -list configure

Path: [built-in]

Name           Value
-------------------------------------------------------------------------------
FEATURES       OpenMP
NAME           ImageMagick
QuantumDepth   16

Path: C:\Program Files\ImageMagick-6.8.8-Q16\configure.xml

Name           Value
-------------------------------------------------------------------------------
CC             vs10
COPYRIGHT      Copyright (C) 1999-2014 ImageMagick Studio LLC
DELEGATES      bzlib freetype jpeg jp2 lcms png tiff x11 xml wmf zlib
FEATURES       OpenMP
HOST           Windows
LIB_VERSION    0x688
LIB_VERSION_NUMBER 6,8,8,5
NAME           ImageMagick
RELEASE_DATE   2014-03-01
VERSION        6.8.8
WEBSITE        http://www.imagemagick.org
I just need imagemagick to do this simple conversion. It would take me hours if I were to use photoshop due to hundreds of pictures need editting.
thanks for the help. : )

Re: Alpha Background using another image. Multi-files.

Posted: 2014-02-15T16:51:55-07:00
by fmw42
You will have to write a script to loop over each image, since the command is too complex for mogrify. I am not a Windows user, but this works in unix.

# line1: read the two images
# line2: copy the character image and extract its alpha channel
# line3: copy the character image, turn off its alpha channel, make the image transparent where it is pink
# line4: copy the back image and resize it to match the character image
# line5: copy the images from line 3 and line 4 and composite them together so that the back image shows where the character image was formerly pink and is now transparent
# line6: delete the two original images and the images from lines 3 and 4, then put the saved alpha channel back into the processed image from line 5

Unix syntax

Code: Select all

convert character.png back.png \
\( -clone 0 -channel a -separate +channel \) \
\( -clone 0 -alpha off -fuzz 1% -transparent "rgb(248,0,248)" \) \
\( -clone 1 -resize 114x108 \) \
\( -clone 4 -clone 3 -compose over -composite \) \
-delete 0,1,3,4 +swap -alpha off -compose copy_opacity -composite character_new.png

The equivalent in Windows syntax is

Code: Select all

convert character.png back.png ^
( -clone 0 -channel a -separate +channel ) ^
( -clone 0 -alpha off -fuzz 1% -transparent "rgb(248,0,248)" ) ^
( -clone 1 -resize 114x108 ) ^
( -clone 4 -clone 3 -compose over -composite ) ^
-delete 0,1,3,4 +swap -alpha off -compose copy_opacity -composite character_new.png
Perhaps one of the other Windows users may be able to help you with a bat script file.

See http://www.imagemagick.org/Usage/windows/

Re: Alpha Background using another image. Multi-files.

Posted: 2014-02-15T17:44:42-07:00
by wmichaelv
WOW, it works!!!!! Thanks man. : D


Just need to make it accept and produce multi files.

Re: Alpha Background using another image. Multi-files.

Posted: 2014-02-15T17:52:01-07:00
by wmichaelv
Sorry for double post.

I did this and it works like magic.

Code: Select all

 FOR %a in (character0*.png) DO convert %a back.png ^
( -clone 0 -channel a -separate +channel ) ^
( -clone 0 -alpha off -fuzz 1% -transparent "rgb(248,0,248)" ) ^
( -clone 1 -resize 114x108 ) ^
( -clone 4 -clone 3 -compose over -composite ) ^
-delete 0,1,3,4 +swap -alpha off -compose copy_opacity -composite new%a
The results are in newcharacter0* though, but that's fine, I can do work around it. : D

Many thanks, fmw42 for the awesome script.