def validate(self): if len(self.args) == 0: self.parser.print_help() sys.exit(0) self.options.input = self.args.pop(0) if self.options.output: pass elif self.options.output == '-': self.options.output = 'output.' + self.options.type.lower() else: basename = os.path.splitext(self.options.input)[0] ext = '.%s' % self.options.type.lower() self.options.output = basename + ext self.options.type = self.options.type.upper() try: imagedraw.create(self.options.type, None) except: msg = "unknown format: %s" % self.options.type raise RuntimeError(msg) if self.options.size: matched = re.match('^(\d+)x(\d+)$', self.options.size) if matched: self.options.size = [int(n) for n in matched.groups()] else: msg = "--size option must be formatted as WIDTHxHEIGHT." raise RuntimeError(msg) if self.options.type == 'PDF': try: import reportlab.pdfgen.canvas reportlab.pdfgen.canvas except ImportError: msg = "could not output PDF format; Install reportlab." raise RuntimeError(msg) if self.options.ignore_pil: msg = "WARNING: --ignore-pil option is deprecated " + \ "(detect automatically).\n" sys.stderr.write(msg) if self.options.nodoctype and self.options.type != 'SVG': msg = "--nodoctype option work in SVG images." raise RuntimeError(msg) if self.options.transparency is False and self.options.type != 'PNG': msg = "--no-transparency option work in PNG images." raise RuntimeError(msg) if self.options.config and not os.path.isfile(self.options.config): msg = "config file is not found: %s" % self.options.config raise RuntimeError(msg) if self.options.fontmap and not os.path.isfile(self.options.fontmap): msg = "fontmap file is not found: %s" % self.options.fontmap raise RuntimeError(msg)
def validate(self): if len(self.args) == 0: self.parser.print_help() sys.exit(0) self.options.input = self.args.pop(0) if self.options.output: pass elif self.options.output == '-': self.options.output = 'output.' + self.options.type.lower() else: basename = os.path.splitext(self.options.input)[0] ext = '.%s' % self.options.type.lower() self.options.output = basename + ext self.options.type = self.options.type.upper() try: imagedraw.create(self.options.type, None, debug=self.options.debug) except Exception: msg = "unknown format: %s" % self.options.type raise RuntimeError(msg) if self.options.size: matched = re.match(r'^(\d+)x(\d+)$', self.options.size) if matched: self.options.size = [int(n) for n in matched.groups()] else: msg = "--size option must be formatted as WIDTHxHEIGHT." raise RuntimeError(msg) if self.options.type == 'PDF': try: import reportlab.pdfgen.canvas reportlab.pdfgen.canvas except ImportError: msg = "could not output PDF format; Install reportlab." raise RuntimeError(msg) if self.options.ignore_pil: warning("--ignore-pil option is deprecated " "(detect automatically).") if self.options.nodoctype and self.options.type != 'SVG': msg = "--nodoctype option work in SVG images." raise RuntimeError(msg) if self.options.transparency is False and self.options.type != 'PNG': msg = "--no-transparency option work in PNG images." raise RuntimeError(msg) if self.options.config and not os.path.isfile(self.options.config): msg = "config file is not found: %s" % self.options.config raise RuntimeError(msg) if self.options.fontmap and not os.path.isfile(self.options.fontmap): msg = "fontmap file is not found: %s" % self.options.fontmap raise RuntimeError(msg)
def __init__(self, _format, diagram, filename=None, **kwargs): self.format = _format.upper() self.diagram = diagram self.fill = kwargs.get('fill', (0, 0, 0)) self.badgeFill = kwargs.get('badgeFill', 'pink') self.filename = filename self.shadow = self.shadow_colors[self.format.upper()] if self.format == 'PNG' and kwargs.get('antialias'): self.scale_ratio = 2 else: self.scale_ratio = 1 self.drawer = imagedraw.create(self.format, self.filename, filters=['linejump'], scale_ratio=self.scale_ratio, **kwargs) self.metrics = self.create_metrics(kwargs.get('basediagram', diagram), drawer=self.drawer, **kwargs) if self.scale_ratio == 2: self.metrics = AutoScaler(self.metrics, scale_ratio=self.scale_ratio) self.drawer.set_canvas_size(self.pagesize()) self.drawer.set_options(jump_radius=self.metrics.cellsize / 2)
def __init__(self, _format, diagram, filename=None, **kwargs): self.format = _format.upper() self.diagram = diagram self.fill = kwargs.get('fill', (0, 0, 0)) self.badgeFill = kwargs.get('badgeFill', 'pink') self.filename = filename self.shadow = self.shadow_colors[self.format.upper()] if self.format == 'PNG' and kwargs.get('antialias'): self.scale_ratio = 2 else: self.scale_ratio = 1 self.drawer = imagedraw.create(self.format, self.filename, filters=['linejump'], scale_ratio=self.scale_ratio, **kwargs) self.metrics = self.create_metrics(kwargs.get('basediagram', diagram), drawer=self.drawer, fontmap=kwargs.get('fontmap')) if self.scale_ratio == 2: self.metrics = AutoScaler(self.metrics, scale_ratio=self.scale_ratio) self.drawer.set_canvas_size(self.pagesize()) self.drawer.set_options(jump_radius=self.metrics.cellsize / 2)