summaryrefslogtreecommitdiffstats
path: root/share/extensions/raster_output_jpg.py
blob: 42350449311bf2d920fa2ecd8adbfaa4d9ae577a (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
#!/usr/bin/env python
"""
Convert PNG to Jpeg using Raster Output extension.
"""

import inkex


class JpegOutput(inkex.RasterOutputExtension):
    multi_inx = True  # XXX Remove this after refactoring

    def add_arguments(self, pars):
        pars.add_argument("--tab")
        pars.add_argument("--quality", type=int, default=90)
        pars.add_argument("--progressive", type=inkex.Boolean, default=False)

    def save(self, stream):
        self.img.convert("RGB").save(
            stream,
            format="jpeg",
            quality=self.options.quality,
            dpi=self.img.info["dpi"],
            progressive=self.options.progressive,
        )


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