Make the background-removing script more generic
This commit is contained in:
@@ -25,17 +25,43 @@
|
||||
# As might be obvious from the below commands, running this script
|
||||
# requires that ImageMagick is installed.
|
||||
#
|
||||
# Note that this script is not at all generic. If you wanted to use it
|
||||
# on other images you would at minimum have to edit the canvas size
|
||||
# specified in the command.
|
||||
# To reproduce the crystal soul and living statue work, use the following params:
|
||||
# ./remove-bg.sh 113x148 back.png fore.png mask.png out.png
|
||||
#
|
||||
|
||||
if [ $# != 5 ]; then
|
||||
echo 'Usage:'
|
||||
echo " $0 <size> <back> <fore> <mask> <out>"
|
||||
echo
|
||||
echo ' <size> The size of the image, eg 28x36'
|
||||
echo ' <back> The path of the background image'
|
||||
echo ' <fore> The path of the foreground image'
|
||||
echo ' <mask> The path of the masking image'
|
||||
echo ' <out> The path for the output image'
|
||||
echo
|
||||
echo 'All parameters are required.'
|
||||
echo 'If it fails, check im_error.txt for ImageMagick errors.'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ -z `which convert` ]; then
|
||||
echo 'Error! You need to install ImageMagick before you'
|
||||
echo 'can use this script.'
|
||||
exit
|
||||
fi
|
||||
|
||||
if [ ! -e $2 -o ! -e $3 -o ! -e $4 ]; then
|
||||
echo 'Error! Could not find one of the input files!'
|
||||
echo 'Make sure you spelled them all correctly.'
|
||||
exit
|
||||
fi
|
||||
|
||||
convert \
|
||||
-size 113x148 canvas:white -alpha set \
|
||||
back.png fore.png -channel A -fx "@calc-alpha.fx" \
|
||||
back.png fore.png -channel RGB -fx "@apply-alpha.fx" \
|
||||
-size $1 canvas:white -alpha set \
|
||||
$2 $3 -channel A -fx "@calc-alpha.fx" \
|
||||
$2 $3 -channel RGB -fx "@apply-alpha.fx" \
|
||||
intermediate.png 2>| im_error.txt
|
||||
|
||||
convert intermediate.png fore.png mask.png -composite out.png
|
||||
convert intermediate.png $3 $4 -composite $5
|
||||
|
||||
rm intermediate.png
|
||||
|
Reference in New Issue
Block a user