-2

The conversion of .jpg file to .tiff file in python.

I have tried the following two approaches but while using the output tiff file in my project, it doesn't support it.

import aspose.words as aw

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

shape = builder.insert_image("0.jpg")
shape.image_data.save("/TIFFs/0.tiff")
from PIL import Image

im = Image.open('0.jpg')
im.save("/TIFFs/0.tiff", 'TIFF')
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
Cosmo
  • 31
  • 6
  • you mean rename, or actually convert the image itself? – Kevin C Nov 16 '22 at 11:26
  • Does the code throw any error? – Jamiu S. Nov 16 '22 at 11:35
  • @Vineeth Sai, Can you provide some more information about your question? How it should look like? – Pravin Nov 16 '22 at 11:37
  • @KevinC I have to actually convert it. – Cosmo Nov 16 '22 at 11:41
  • @JamiuShaibu no, it doesn't throw any error. – Cosmo Nov 16 '22 at 11:41
  • @Pravin it has to just convert the jpg file to tiff file. Nothing more complicated. – Cosmo Nov 16 '22 at 11:42
  • @romaingal yes, i've tried that as well but it doesn't work either. – Cosmo Nov 16 '22 at 11:43
  • What does "doensn't work" mean? What error are you getting? – Sembei Norimaki Nov 16 '22 at 11:46
  • try using double `//` on your directory where you are saving the image to see if that works – Jamiu S. Nov 16 '22 at 11:46
  • @SembeiNorimaki I am getting the following error in my project: ValueError: The parameter `image` must be a 2-dimensional array But when I tried online conversion of jpg to tiff and used that tiff file, it works. – Cosmo Nov 16 '22 at 11:48
  • 1
    don't write relevant information as a comment. Edit your question and post the full traceback, so we can see exactly in what line your error is and what exactly does the error say – Sembei Norimaki Nov 16 '22 at 11:48
  • @JamiuShaibu yes, tried it but still not working. – Cosmo Nov 16 '22 at 11:50
  • @SembeiNorimaki I'm sure the issue is with the conversion of the file. It is not in my project code for sure, that is the reason I asked this question. – Cosmo Nov 16 '22 at 11:52
  • Ok, then without seeing error traceback and with you being sure that it's not your code that fails, what do you expect us to do? If your code has nothing wrong, then there's nothing to solve. You mention that the error says `ValueError: The parameter image must be a 2-dimensional array` so that strongly suggest something wrong with the code. – Sembei Norimaki Nov 16 '22 at 11:52
  • @SembeiNorimaki Hey, I just mentioned right. Everything works when I use the online conversion of jpg to tiff (I mean the websites which convert them). So isn't it obvious that there is nothing wrong with the code? – Cosmo Nov 16 '22 at 11:59
  • What do online converters have to do with your code? Of course if you use another tool that has been tested that works it will work. Yours appear to not do the conversion, which means, there's nothing wrong with the image but with your code. And without seeing the traceback error that we requested there's nothing else we can do. – Sembei Norimaki Nov 16 '22 at 12:03
  • @SembeiNorimaki Okay sure, I will check it and post a new question with that code if it still doesn't work. Thank you. – Cosmo Nov 16 '22 at 12:08

1 Answers1

0

If you go to the PIL documentation about TIFF format

https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#tiff

You will notice that it says:

Note

Beginning in version 5.0.0, Pillow requires libtiff to read or write compressed files. 
Prior to that release, Pillow had buggy support for reading Packbits, 
LZW and JPEG compressed TIFFs without using libtiff.

So make sure you have libtiff installed as specified in the documentation, and update your PIL library to >=5.0.0 if you are using an older version

Sembei Norimaki
  • 745
  • 1
  • 4
  • 11