Exemplo n.º 1
0
    except KeyError:
	raise IOError, "cannot write mode %s as JPEG" % im.mode
    # get keyword arguments
    im.encoderconfig = (_fetch(im.encoderinfo, "quality", 0),
			im.encoderinfo.has_key("progressive"),
			_fetch(im.encoderinfo, "smooth", 0),
			im.encoderinfo.has_key("optimize"),
			_fetch(im.encoderinfo, "streamtype", 0))
    ImageFileH._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])

def _save_hack(im, fp, filename):
    # ALTERNATIVE: handle JPEGs via the IJG command line utilities.
    import os
    file = im._dump()
    os.system("cjpeg %s >%s" % (file, filename))
    try: os.unlink(file)
    except: pass

# -------------------------------------------------------------------q-
# Registry stuff

ImageH.register_open("JPEG", JpegImageFile, _accept)
ImageH.register_save("JPEG", _save)

ImageH.register_extension("JPEG", ".jfif")
ImageH.register_extension("JPEG", ".jpe")
ImageH.register_extension("JPEG", ".jpg")
ImageH.register_extension("JPEG", ".jpeg")

ImageH.register_mime("JPEG", "image/jpeg")
Exemplo n.º 2
0
    except KeyError:
	raise IOError, "cannot write mode %s as JPEG" % im.mode
    # get keyword arguments
    im.encoderconfig = (_fetch(im.encoderinfo, "quality", 0),
			im.encoderinfo.has_key("progressive"),
			_fetch(im.encoderinfo, "smooth", 0),
			im.encoderinfo.has_key("optimize"),
			_fetch(im.encoderinfo, "streamtype", 0))
    ImageFileH._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])

def _save_hack(im, fp, filename):
    # ALTERNATIVE: handle JPEGs via the IJG command line utilities.
    import os
    file = im._dump()
    os.system("cjpeg %s >%s" % (file, filename))
    try: os.unlink(file)
    except: pass

# -------------------------------------------------------------------q-
# Registry stuff

ImageH.register_open("JPEG", JpegImageFile, _accept)
ImageH.register_save("JPEG", _save)

ImageH.register_extension("JPEG", ".jfif")
ImageH.register_extension("JPEG", ".jpe")
ImageH.register_extension("JPEG", ".jpg")
ImageH.register_extension("JPEG", ".jpeg")

ImageH.register_mime("JPEG", "image/jpeg")
Exemplo n.º 3
0
		 o16(offset[0]) +	# offset
		 o16(offset[1]) +
		 o16(im.size[0]) +	# size
		 o16(im.size[1]) +
		 chr(0) +		# flags
		 chr(8))		# bits

	ImageFileH._save(im, fp, [("gif", (0,0)+im.size, 0, RAWMODE[im.mode])])

	fp.write("\0") # end of image data

    finally:
	del im.encoderinfo

    return fp.data


# --------------------------------------------------------------------
# Registry

ImageH.register_open(GifImageFile.format, GifImageFile, _accept)
ImageH.register_save(GifImageFile.format, _save)
ImageH.register_extension(GifImageFile.format, ".gif")
ImageH.register_mime(GifImageFile.format, "image/gif")

#
# Uncomment the following line if you wish to use NETPBM/PBMPLUS
# instead of the built-in "uncompressed" GIF encoder

# Image.register_save(GifImageFile.format, _save_netpbm)
Exemplo n.º 4
0
        # local image header
        fp.write("," + o16(offset[0]) +  # offset
                 o16(offset[1]) + o16(im.size[0]) +  # size
                 o16(im.size[1]) + chr(0) +  # flags
                 chr(8))  # bits

        ImageFileH._save(im, fp,
                         [("gif", (0, 0) + im.size, 0, RAWMODE[im.mode])])

        fp.write("\0")  # end of image data

    finally:
        del im.encoderinfo

    return fp.data


# --------------------------------------------------------------------
# Registry

ImageH.register_open(GifImageFile.format, GifImageFile, _accept)
ImageH.register_save(GifImageFile.format, _save)
ImageH.register_extension(GifImageFile.format, ".gif")
ImageH.register_mime(GifImageFile.format, "image/gif")

#
# Uncomment the following line if you wish to use NETPBM/PBMPLUS
# instead of the built-in "uncompressed" GIF encoder

# Image.register_save(GifImageFile.format, _save_netpbm)
Exemplo n.º 5
0
	    pass
	def append(self, chunk):
	    self.data.append(chunk)

    def append(fp, cid, *data):
	data = string.join(data, "")
	hi, lo = ImageH.core.crc32(data, ImageH.core.crc32(cid))
	crc = o16(hi) + o16(lo)
	fp.append((cid, data, crc))

    fp = collector()

    try:
	im.encoderinfo = params
	_save(im, fp, None, append)
    finally:
	del im.encoderinfo

    return fp.data


# --------------------------------------------------------------------
# Registry

ImageH.register_open("PNG", PngImageFile, _accept)
ImageH.register_save("PNG", _save)

ImageH.register_extension("PNG", ".png")

ImageH.register_mime("PNG", "image/png")
Exemplo n.º 6
0
        def append(self, chunk):
            self.data.append(chunk)

    def append(fp, cid, *data):
        data = string.join(data, "")
        hi, lo = ImageH.core.crc32(data, ImageH.core.crc32(cid))
        crc = o16(hi) + o16(lo)
        fp.append((cid, data, crc))

    fp = collector()

    try:
        im.encoderinfo = params
        _save(im, fp, None, append)
    finally:
        del im.encoderinfo

    return fp.data


# --------------------------------------------------------------------
# Registry

ImageH.register_open("PNG", PngImageFile, _accept)
ImageH.register_save("PNG", _save)

ImageH.register_extension("PNG", ".png")

ImageH.register_mime("PNG", "image/png")