summaryrefslogtreecommitdiffstats
path: root/share/extensions/raster_output_tiff.py
blob: 1594b7fcc3c750347116ee39accaf70349ac8fa7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/env python
"""
Convert PNG to Tiff using Raster Output extension.
"""

import io
import inkex


class TiffOutput(inkex.RasterOutputExtension):
    def add_arguments(self, pars):
        pars.add_argument("--tab")
        pars.add_argument("--compression", default=None)
        pars.add_argument("--quality", type=int, default=90)

    def save(self, stream):
        tempstream = io.BytesIO()
        self.img.save(
            tempstream,
            format="tiff",
            compression=(self.options.compression or None),
            dpi=self.img.info["dpi"],
            quality=100,
        )
        stream.write(tempstream.getvalue())
        # TODO: Add other fields such as copyright etc.


if __name__ == "__main__":
    TiffOutput().run()