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

import inkex


class WebpOutput(inkex.RasterOutputExtension):
    def add_arguments(self, pars):
        pars.add_argument("--tab")
        pars.add_argument("--quality", type=int, default=80)
        pars.add_argument("--speed", type=int, default=0)
        pars.add_argument("--lossless", type=inkex.Boolean, default=True)

    def save(self, stream):
        self.img.save(
            stream,
            format="webp",
            quality=self.options.quality,
            lossless=self.options.lossless,
            method=self.options.speed,
        )


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