Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
List layers without loading image?
#6
This quick done and dirty piece of python3 code should work...
Replace "test.xcf" by the path to your file and run it from a terminal


Code:
#!/usr/bin/env python3


if __name__ == "__main__":
    
    filename = "test.xcf"
    
    # 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)
            
            tmp = int.from_bytes(f.read(4), "big")
            name = f.read(tmp).decode("utf-8")
            print(name)

            f.seek(saved_pos, 0)
Reply


Messages In This Thread
RE: List layers without loading image? - by tmanni - 02-07-2021, 07:49 PM

Forum Jump: