forked from silveira/openpixels
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextract_layers.sh
More file actions
executable file
·46 lines (37 loc) · 1.07 KB
/
extract_layers.sh
File metadata and controls
executable file
·46 lines (37 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
# TODO check if xcfinfo and xcf2png exists
# TODO put a -v --verbose option
# check if we have the parameter
if [ $# -ne 1 ]
then
echo "Usage:"
echo "\t$0 FILE"
exit
fi
# the first parameter is a xcf filename
filename=$1
# use xcfinfo first line to retrieve the number of the layers in the XCF file
layers_count=`xcfinfo $filename | head -1 | cut -d',' -f3 | cut -d' ' -f2`
# use xcfinfo to retrieve the name of each layer. use layers_count to ignore the first line.
# layers can NOT have spaces in the name
layers_names=`xcfinfo $filename | cut -d' ' -f5 | tail -$(($layers_count))`
# directory to put layers
destdir='layers'
mkdir $destdir 2>> /dev/null
# extract layer by layer as a png using xcf2png
for layer_name in $layers_names
do
command="xcf2png $filename $layer_name --output $layer_name.png"
echo -n "Extracting $layer_name... "
$command
if [ $? -eq 0 ]
then
mv $layer_name.png $destdir
echo "OK"
else
echo "FAIL"
echo "Problem executing: $command"
fi
done
# TODO count how many layers were succesfully extracted
# TODO use layer's alpha level