Ejemplo n.º 1
0
    def to_file(self, filename, mode='P'):
        """Save the graphic to an image file.

        The output format is selected based on the filename extension.
        For example, "file.jpg" saves to JPEG format. If the file has
        no extension, PNG format is used.

        Special cases: ".lmp" saves the raw lump data, and ".raw" saves
        the raw pixel data.

        `mode` may be be 'P' or 'RGB' for palette or 24 bit output,
        respectively. However, .raw ignores this parameter and always
        writes in palette mode."""

        format = os.path.splitext(filename)[1].upper()
        if   format == '.LMP': util.writefile(filename, self.data)
        elif format == '.RAW': util.writefile(filename, self.to_raw())
        else:
            im = self.to_Image()
            om = im.convert(mode)
            if format:
                om.save(filename)
            else:
                om.save(filename, "PNG")
Ejemplo n.º 2
0
    def to_file(self, filename, mode='P'):
        """Save the graphic to an image file.

        The output format is selected based on the filename extension.
        For example, "file.jpg" saves to JPEG format. If the file has
        no extension, PNG format is used.

        Special cases: ".lmp" saves the raw lump data, and ".raw" saves
        the raw pixel data.

        `mode` may be be 'P' or 'RGB' for palette or 24 bit output,
        respectively. However, .raw ignores this parameter and always
        writes in palette mode."""

        format = os.path.splitext(filename)[1].upper()
        if format == '.LMP': util.writefile(filename, self.data)
        elif format == '.RAW': util.writefile(filename, self.to_raw())
        else:
            im = self.to_Image()
            om = im.convert(mode)
            if format:
                om.save(filename)
            else:
                om.save(filename, "PNG")
Ejemplo n.º 3
0
 def to_file(self, target):
     """Write data to a file. Target may be a path name string
     or a file-like object (with a `write` method)."""
     util.writefile(target, self.data)
Ejemplo n.º 4
0
 def to_file(self, target):
     """Write data to a file. Target may be a path name string
     or a file-like object (with a `write` method)."""
     util.writefile(target, self.data)