#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Convert a document to an Image Run with a command like scribus -g -py export_to_image.py testdoc.sla -ns -g -py export_to_image.py -type 'PNG' -quality 100 -transparentBkgnd 1 -name 'test.png' -scale 100 -dpi 96 You can set any "image" attribute with "-attribute value". Tested with scribus 1.5.2.svn r21147 Author: William Bader, Director of Research and Development, SCS, http://www.newspapersystems.com 15Sep15 wb initial version 31Mar16 Jural Fedel simplified, added support for page ranges 31Mar16 Andres Gomez replaced 8 spaces indent with 4 spaces. """ import scribus import sys import ast def main(argv): print(argv) image = scribus.ImageExport() i = 1 while i < len(argv): if (argv[i][0] != '-'): raise Exception("Image option expected instead of: '{0}'".format(argv[i])) name = argv[i][1:] image_attr = getattr(image, name) i = i + 1 try: value = argv[i] except: msg = "Option '{0}' require value".format(name) raise Exception(msg) if isinstance(image_attr, str): setattr(image, name, value) else: val = None try: val = ast.literal_eval(value) except: msg = "'{0}' =/= '{1}'".format(name, value) raise ValueError(msg) setattr(image, name, val) i = i + 1 image.save() # start the script if __name__ == '__main__': main(sys.argv)