This is possibly the most annoying thing I've encountered for a seemingly simple task.All I need to do is take my 32-bit per channel image data and save it as layers in a TIFF or preferrably PSD that Photoshop and After Effects can read. To date, all they will import is the composite.
The documentation for TIFF is ancient and there are no examples I can find of how to properly set the TIFF tag 37724 for layer data in Python.
Writing multipage TIFF is easy, but Adobe does not support them for some unknown reason. Even Apple Preview can read Multipage Tiff. But Photoshop, the "industry standard" cannot. 🙄
If someone at Adobe can please clear this up, it would be appreciated because I'm hitting brick walls and even the creators of python image libraries have no idea how to code the tag because it's so poorly documented.
If you guys really want to keep this proprietary for PSDs, then write a C binary or something that python can read in as a module so we can easily save layered PSDs with a simple arg.
This is as close as I've gotten. Photoshop sees the layer data but says it can't understand it, and just imports the composite image.
data_block = bytes('Adobe Photoshop Document Data Block', 'ascii') + b'\x00'
bim = bytes('8BIM', 'ascii')
layer = bytes('Layr', 'ascii')
with tifffile.TiffWriter(outtif) as tiff:
for img in image_data:
img_bytes = img.tobytes()
total_bytes_length = int(len(img_bytes)) - int(len(data_block))
image_data_tuple = (data_block, bim, layer, total_bytes_length)
s = struct.Struct('36s 4s 4s I')
image_source_data = s.pack(*image_data_tuple)
tiff.save(img, extratags=[(37724, 7, None, image_source_data, False)])