1

I've been trying to see if I can speed up a part of a pipeline where we're atlassing images (previously using Photoshop which is horrendously slow due to GUI updates) and I'm looking to see if I can use Pillow to create a tiff atlas.

Now I know I can make an atlas out of images (have this working already) in Pillow but I can not for the life of me get it to have the images as layers so that way if someone needs to edit (move images around for example) at a later date they can easily do so.

from PIL import Image
import os

cwd = os.getcwd()
atlas = Image.new('RGBA', (2048, 2048),(0,0,0,0))
tgas = [x for x in os.listdir(cwd) if x.lower().endswith(".tga")]
count = 0
imgs = []

for img in tgas:
    print(img)
    im = Image.open(img)
    temp = Image.new('RGBA', (2048, 2048),(0,0,0,0))
    if count == 0:
        atlas.paste(im,(0, 0))
    elif count == 1:
        atlas.paste(im, (1024,0))
    elif count == 2:
        atlas.paste(im, (0, 1024))
    elif count == 3:
        atlas.paste(im, (1024,1024))
    count +=1
    imgs.append(atlas)
    im.close()

    atlas.save("atlasTest.tif", tags="37724", compression="None", save_all=True, append_images=imgs)

I found another SO post about the reading of tiff to see if it has layers (hence the tags="37724" )but it does not seem to work on save.

This method would save a ton of time but I don't think I can use it if I can't get the layers. I originally was going to try to make it save out the atlas'd images to a PSD but can't seem to make layers in that either... Was able to also do "multi-page" but that doesn't seem to be what I'm looking for either, it really would have to be layers just cause it would be easier to deal with later on. Any help would be great (Also, please don't judge my hard coded image placement, was done quickly as a test and didn't feel like doing the math for it :P )

TEvashkevich
  • 43
  • 11
  • This looks very related... https://stackoverflow.com/a/19541123/2836621 – Mark Setchell Sep 22 '18 at 21:38
  • Nope, Multi-Page is not what I'm attempting to make here. I'd like to create something like the following: [Example Layout](https://imgur.com/K8ZlhBi) where in py I put all the images together in an atlas like so, but on opening again I can still have access to each image as a layer. This is doable IN Photoshop itself. – TEvashkevich Sep 22 '18 at 23:06
  • Also looking at even just writing the images as layers to a PSD with pytoshop but can't seem to get layers to actually work (which is very frustrating) – TEvashkevich Sep 23 '18 at 03:15
  • 1
    ended up using a combination of Pillow and Pytoshop to achieve my end result (and also did it in tga instead as I didn't explicitly need tiff in the end) – TEvashkevich Oct 31 '18 at 12:33
  • I know this is from a while back but could you share the solution you found? – Sy Ker Feb 24 '22 at 07:12

0 Answers0