Correct way to write a multi-layered tiff file for reading in Photoshop?
See original GitHub issueHello again
I’ve been trying to use imageio to write a multi-layered TIFF file that can be read by Photoshop. I prepared a variable of multiple numpy arrays (the images read in by imageio).
If I use mimwrite
I seem to only get one layer in Photoshop. It is RGB and at the correct bit depth. I’m using tifffile as the plugin driver.
By LAYERS, I mean individual, editable layers that each contain their own independent RGB data in Photoshop. If layered files are written out of Photoshop as TIFF without flattening, they can be read back in just fine, so not sure why this is not working.
When searching for an answer, most people seem to refer to color channels as layers (R, G, B, Alpha1, Alpha2) when working with images in Python. They refer to “Multipage” TIFF, so maybe that’s the terminology. I didn’t see anything in the imageio docs about writing Multipage, only a patch note saying Multipage was supported when reading TIFF files.
The data seems like it’s in the file because I merged 3 files that were 1.1 MB each and the resulting TIFF is 3.2MB, but Photoshop only seems to recognize the first file layer of RGB data that was read in. There are only 3 channels in the file (R,G,B).
Not sure if I’m missing something, if I have to use some kind of loop to create the file and then add each opened image as a layer, or if there’s some extra data that needs to be added to the file for Photoshop to recognize them properly.
Here’s the test code (applicable part):
image_data = []
for idx, f in enumerate(filepaths):
image = imageio.imread(f)
image_data.append(image)
image_array = np.array(image_data)
imageio.mimwrite(outtif, image_array, format="tif")
# I tried this also with same result, since it seems to be a numpy array when opened
for idx, f in enumerate(filepaths):
image = imageio.imread(f)
image_data.append(image)
imageio.mimwrite(outtif, image_data, format="tif")
Printing the shape of image_array
produces:
(3, 300, 300, 3)
Here’s the expected results in Photoshop:
Actual result:
Would appreciate a point in the right direction.
Thanks
Issue Analytics
- State:
- Created 2 years ago
- Comments:30 (13 by maintainers)
Top GitHub Comments
@FirefoxMetzger
Finding files in the bowels of my archive was proving to be a pain, so I just made something new.
I made a simple logo for imageIO in Illustrator, then brought it into Photoshop, tweaked and made it 32-bit.
Included in the Zip
All files were exported using ProEXR. I made 5 EXR versions and included the masters. All are sRGB color space. I can do rec709 or other color space versions if you need.
Notes
The compressed EXRs use lossless compression. The uncompressed layered EXR is almost 400MB. The others are below 20 and 10. Just be aware wherever you uncompress it, it’s about 500MB of files, but only 21MB zipped.
The included TIFF is just in case you or @cgohlke try to dissect it at some point. I also included the After Effects file just so you have it if you need it in the future.
Layer Setup:
Some layers in the PSD have editable layer masks, while the rest have burnt in opacity. The background is a solid color as a locked background layer. I did this to test the exporter, but also so if you want to investigate the differences in layers with masks vs opacity. ProEXR exported them all the same with no problems and Photoshop saved all the data in the TIFF.
One layer has a generic name “Layer 1”. I did this to see if it mattered since it was a default and had a space in the name.
I didn’t use any overlay modes (multiply, add, etc), but can make another test with them if needed.
Lastly, the background is not pure black and the “whites” are not pure white. Colors are accurate. If you want me to push things above white and below black to test them, let me know.
Interest thing with ProEXR:
It actually saves all the layer data and keeps the opacity of the layer as an attribute, so when I import into After Effects, the opacity of the layer is adjustable. I thought it would bake in the master layer opacity, but glad it doesn’t. If you haven’t used Photoshop, besides the opacity of pixels in a layer, each layer has an overall opacity control from 0-100%. This is the data ProEXR is also keeping intact.
It’s also saving text data in the file, which shows up as a hidden layer in the AE comp with notes about all the layers.
Here is the text data:
Files
A PNG preview from Photoshop, a screenshot of the Photoshop layers, followed by a screenshot of compositions and layers in After Effects. If you’re curious, the font is Source Serif Pro from Google Fonts. Didn’t want you to run into licensing issues if I used a font I paid for (even though it should technically be okay).
imageIO_Logo_EXR.zip
I published what I got so far at PyPI and GitHub.
Install with
python -m pip install psdtags tifffile imagecodecs matplotlib
To view the layer and mask information in a layered TIFF file from a command line: