Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

write .tif to be read with photoshop #3

Closed
StefanBaar opened this issue Nov 8, 2022 · 3 comments
Closed

write .tif to be read with photoshop #3

StefanBaar opened this issue Nov 8, 2022 · 3 comments

Comments

@StefanBaar
Copy link

Is it possible to put multiple images, as layers, into a tif file and have them be read by photoshop.

I tried the following,

with tifffile.TiffWriter('temp.tif') as tiff:
    for img in data:
        data_block = bytes('Adobe Photoshop Document Data Block', 'ascii') + b'\x00'
        bim = bytes('8BIM', 'ascii')
        layer = bytes('Layr', 'ascii')
        img_bytes = img.tobytes()
        img_len = len(img_bytes)
        img_len_bytes = bytes(str(img_len), 'ascii')
        all_bytes = data_block + bim + layer + img_len_bytes
        byte_length = len(all_bytes) - len(data_block)
        bytes_bytes = bytes(byte_length)
        allll = all_bytes + bytes_bytes
        metad = {"37724": str(allll)}
        
        tiff.save(img, metadata=metad)
tif.close()

which works with preview (on mac) but not photoshop. Photoshop only sees the first layer...

@cgohlke
Copy link
Owner

cgohlke commented Nov 13, 2022

The code does not use the psdtags library.

Use the extratags argument in tifffile to write a valid ImageSourceData binary structure to tag #37724, e.g., extratags=[(37724, 7, len(imagesourcedata), imagesourcedata, True)]

@cgohlke cgohlke closed this as completed Nov 13, 2022
@cgohlke
Copy link
Owner

cgohlke commented Dec 14, 2022

See issue #4.

@cgohlke
Copy link
Owner

cgohlke commented Feb 8, 2023

See also examples/layered_tiff.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants