10-02-2021, 10:58 AM
(This post was last modified: 10-02-2021, 12:30 PM by ChameleonScales.)
I found how to also print whether each layer contains a mask or not (by myself!).
To recap on how to use this script in case anyone's lost, run it like this in the terminal:
Code:
#!/usr/bin/env python3
import sys
PROP_ACTIVE_LAYER = 2
PROP_VISIBLE = 8
if __name__ == "__main__":
filename = sys.argv[1]
# open the file in readonly binary mode
with open(filename, 'rb') as f:
# go to the 30th bytes
f.seek(30, 0)
# read properties
while True:
prop_type = int.from_bytes(f.read(4), "big")
prop_size = int.from_bytes(f.read(4), "big")
f.read(prop_size)
if prop_type == 0: #PROP_END
break
# read layers
while True:
next_layer_offset = int.from_bytes(f.read(8), "big")
if not next_layer_offset: #end of layers offsets
break;
saved_pos = f.tell()
f.seek(next_layer_offset + 12, 0)
name_len = int.from_bytes(f.read(4), "big")
name0 = f.read(name_len).decode("utf-8")
name = name0.replace('\0', '')
print()
print(name)
while True:
prop_type = int.from_bytes(f.read(4), "big")
prop_size = int(int.from_bytes(f.read(4), "big") / 4)
#print(prop_type, "size", prop_size)
for i in range(prop_size):
lastint = int.from_bytes(f.read(4), "big")
if prop_type == PROP_VISIBLE:
print("Visi: %x" % lastint)
elif prop_type == PROP_ACTIVE_LAYER:
print("Active")
elif prop_type == 0: #PROP_END
break
# hierarchy pointer:
hptr = int.from_bytes(f.read(8), "big")
# mask pointer:
mptr = int.from_bytes(f.read(8), "big")
if mptr == 0:
has_mask = 0
else:
has_mask = 1
print("Mask: " + str(has_mask))
f.seek(saved_pos, 0)
To recap on how to use this script in case anyone's lost, run it like this in the terminal:
Code:
./script.py "path/to/my.xcf"