Ejemplo n.º 1
0
    def __init__(self, path, width=0, height=0):
        """Create a document instance from file or totally new.
        @path: Path of the requested image.
        @width: If no path given, width of new document.
        @height: If no path given, height of new document."""

        # Allow debug tracking.
        main.log.allow_tracking(self)

        # If path given.
        self.path = path
        if path:

            # If given file is openraster, load it.
            name, ext = os.path.splitext(path)
            if ext == '.ora':
                ora = OpenRaster(path)
                width, height = ora.get_size()
                self.mime = 'image/openraster'
                self.configure(width, height)
                self.layers = Layers(self)
                ora.load(self)

            # If given file is an image loadable by gtk, load it.
            else:
                info, width, height = gtk.gdk.pixbuf_get_file_info(path)
                self.mime = info['mime_types'][0]
                self.configure(width, height)
                self.layers = Layers(self)
                self.layers.append_from_path(path)
                self.layers.active.name = _('Original')

        # If not path given, create a blank document.
        else:
            self.configure(width, height)
            self.layers = Layers(self)
            self.layers.append_blank(width, height, True)

        # Set canvas and action tracker.
        self.canvas = Canvas(self)
        self.actions = Actions(self)
Ejemplo n.º 2
0
    def export(self, path, format, quality=None):

        # OpenRaster format.
        if format == 'ora':
            ora = OpenRaster(path, 'w')
            ora.save(self)

        # PNG format.
        if format == 'png':
            pixbuf = self.pixbuf
            pixbuf.save(path, format)

        # JPG format.
        if format == 'jpg':
            format = 'jpeg'
            if quality: options = {'quality':str(quality)}
            else: options = {'quality':'90'}
            pixbuf = self.layers.get_noalpha().pixbuf
            pixbuf.save(path, format, options)

        # Print message to stdout.
        main.log.info('saving doc: %s' % path)