Closed ricaun closed 1 week ago
Hi. See what you think of this.
from PIL import Image, TiffImagePlugin
output_filename = "out.tiff"
images = [
Image.new("RGB", (100, 100)),
Image.new("RGB", (100, 100))
]
images[0].info["dpi"] = (100, 100)
images[1].info["dpi"] = (50, 50)
with TiffImagePlugin.AppendingTiffWriter(output_filename, new=True) as tf:
for im in images:
im.save(tf, dpi=im.info["dpi"])
tf.newFrame()
# Open output file
with Image.open(output_filename) as img:
for frame in range(img.n_frames):
img.seek(frame)
print(f"Frame {img} {img.info['dpi']}")
Yes! Great!
TiffImagePlugin.AppendingTiffWriter
works perfectly, exactly what I was looking for.
Thanks for the sample, helps a lot!
I trying to save a Tiff file with multiple images with different dpi.
Looks like is only possible to set one dpi for the whole tiff file, and after looking in the python code for the tiff
_save
, does not seen to have a way to use the currentdpi
for each frame.Here is a code sample that I'm using the join two PNG with different dpi in a single tiff file, and after opening the output tiff file the dpi of the
append_images
is lost.This is the output for that code:
Both frames in the tiff have the same 96 dpi, I need to be 96 and 192, like the source images.