0

[many things were solved since the original question. See the comments below. It remains that the final file only contain the first page, I don't see any warning or error messages]

I saw that in recent version of Pillow added support for saving multipage images, esp. TIFF with im_all.save('test.tiff', save_all=True).

Now it is not clear to me how I should proceed to create a multipage .tiff using a list of .tiff pages to be put together. I couldn't find an example or some indication in the documentation. Do I need to resize each image to the size of the final document ? I made a naive test withmy B&W .tiff which have mode "1"

list_im=[]
im_all=Image.new("1", (2500, 3500))
for i in list_file:
     print i
     im = Image.open(path_tmp+'/'+i)
     print im.format, im.size, im.mode
     list_im.append(im)
     im.close()

im_all.save('test.tiff', save_all=True,append_images=list_im)

but I got the error messages

42526530005_632__0.tiff
TIFF (2445, 3472) 1
42526530005_632__1.tiff
TIFF (2448, 3474) 1
42526530005_632__2.tiff
TIFF (2451, 3471) 1
42526530005_632__3.tiff
TIFF (2454, 3471) 1
42526530005_632__4.tiff
TIFF (2459, 3471) 1
42526530005_632__5.tiff
TIFF (2467, 3472) 1
42526530005_632__6.tiff
TIFF (2452, 3471) 1
Traceback (most recent call last):
  File "master_cost_claims_analyser.py", line 1401, in <module>
    main()
  File "master_cost_claims_analyser.py", line 1398, in main
    args.all_steps)
  File "master_cost_claims_analyser.py", line 565, in cost_claim_analyser_main
    verbose)
  File "H:/DATA/Projects and Documents/Projects/ClaimsCostAnalyzer/ClaimsCostAnalyzerCode/ClaimsExtraction/get_claims_functions.py", line 176, in get_claims
    im_all.save('test.tiff', save_all=True,append_images=list_im)
  File "C:\Program Files\Anaconda2\lib\site-packages\PIL\Image.py", line 1679, in save
    save_handler = SAVE_ALL[format.upper()]
KeyError: 'TIFF'

I am using python 2.7.12 pillow 3.2.0

Do somebody know how we save a list of .tiff page in a multipage .tiff documents ? I guess I am doing something wrong.

Thanks

Fabien

Dr. Fabien Tarrade
  • 1,556
  • 6
  • 23
  • 49
  • your code is truncated. please add missing part. – Jean-François Fabre Nov 02 '16 at 10:26
  • I added the missing "(" but this is a tiny part of the code that is relevant for my issue. I added the full log. Thanks – Dr. Fabien Tarrade Nov 02 '16 at 11:32
  • ok, I didn't realize the new function was only introduce in a latest version. Using Pillow 3.4.2 help a bit. I also added the im.load() instead of im.close() to be sure the connection to the file was closed. With Windows im.close() didn't close the connection and Windows complained it was used by another application. The only issue I got now is that my final file is only 1 page, fully black and the size is 10x higher than all pages together ! No clue. Is my new file not created in the proper way ? – Dr. Fabien Tarrade Nov 02 '16 at 12:21
  • I upgraded to `Pillow-3.4.2` on python 3.4 and I had the same error. Well, can you [edit] your question because with your comment changing it completely it doesn't make much sense now. I'll have a look if the question is accurate. – Jean-François Fabre Nov 02 '16 at 13:24
  • Hi Jean-Francois, which error do you get ? For me I don't get an error but I am getting is the initial file (im_all=Image.new("1", (2500, 3500)) is indeed creating a fully back page). If I use as the first file from my list and try to add the other file with Image.save(..save_all=True,append_images=[..]) I am only getting the first file. Ok, I can try to rephrase a bit the question but my goal is the same. – Dr. Fabien Tarrade Nov 02 '16 at 13:48

1 Answers1

0

the following works as it was suggested on here link :

with PIL.TiffImagePlugin.AppendingTiffWriter("./test.tiff",True) as tf:
for tiff_in in list_file: with open(tiff_in) as tiff_in: im= Image.open(tiff_in) im.save(tf) tf.newFrame()

I am using pillow 4.0.0

Dr. Fabien Tarrade
  • 1,556
  • 6
  • 23
  • 49