libvips / pyvips

python binding for libvips using cffi
MIT License
649 stars 50 forks source link

use set_type add other custom meta data #513

Closed chengdonglin closed 1 month ago

chengdonglin commented 1 month ago

I am trying to add custom metadata to an existing TIFF file using pyvips. However, after adding the metadata, the file size increases significantly (from 50MB to 700MB), and the resulting TIFF file becomes unreadable by OpenSlide.

import pyvips
#
image = pyvips.Image.new_from_file("D:\\data\\example.tif")

image.set_type(pyvips.GValue.gstr_type, "hello", "xxx")

image.write_to_file("output.tif")

any some method to complete this feature?

jcupitt commented 1 month ago

Hello @chengdonglin,

libtiff does not support custom metadata, you'll need to think of some other way to do what you want. For example, OME-TIFF uses a block of XML in the IMAGEDESCRIPTION tag, perhaps you could add something to that.

image.write_to_file("output.tif")

libvips does not keep track of format settings, so if you want to write as an OME-TIFF, you need to set all the flags yourself.