To convert a TIFF image to a JPG image in Python, you can use the PIL
(Python Imaging Library) library. Here’s an example:
from PIL import Image
# Open the TIFF image
tiff_image = Image.open('input_image.tif')
# Convert the TIFF image to JPG
tiff_image.save('output_image.jpg', 'JPEG')
# Close the TIFF image
tiff_image.close()
In this example, we use the Image
module from the PIL
library to open the TIFF image using the Image.open()
method. Make sure you have the PIL
library installed (pip install pillow
) before running the code.
After opening the TIFF image, we use the save()
method to save it as a JPG image. The second argument specifies the file format, in this case, 'JPEG'
for JPG. You can also specify the desired quality of the JPG image by providing an optional quality
parameter (0 to 100, with 100 being the highest quality).
Finally, we close the TIFF image using the close()
method to free up system resources.
After running the code, the TIFF image will be converted and saved as a JPG image with the specified file name (output_image.jpg
in this example).
Note that the resulting JPG image may have different characteristics (e.g., compression, color space) compared to the original TIFF image, as the two formats use different compression algorithms and support different color depths.
+ There are no comments
Add yours