本文整理汇总了Python中lib.pil.Image.register_save方法的典型用法代码示例。如果您正苦于以下问题:Python Image.register_save方法的具体用法?Python Image.register_save怎么用?Python Image.register_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.pil.Image
的用法示例。
在下文中一共展示了Image.register_save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _accept
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
if not _accept(self.fp.read(8)):
raise SyntaxError("Not a GRIB file")
self.fp.seek(offset)
# make something up
self.mode = "F"
self.size = 1, 1
loader = self._load()
if loader:
loader.open(self)
def _load(self):
return _handler
def _save(im, fp, filename):
if _handler is None or not hasattr("_handler", "save"):
raise IOError("GRIB save handler not installed")
_handler.save(im, fp, filename)
# --------------------------------------------------------------------
# Registry
Image.register_open(GribStubImageFile.format, GribStubImageFile, _accept)
Image.register_save(GribStubImageFile.format, _save)
Image.register_extension(GribStubImageFile.format, ".grib")
示例2: _load
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
# include SIMPLE, BITPIX, NAXIS, etc.
self.fp.seek(offset)
# make something up
self.mode = "F"
self.size = 1, 1
loader = self._load()
if loader:
loader.open(self)
def _load(self):
return _handler
def _save(im, fp, filename):
if _handler is None or not hasattr("_handler", "save"):
raise IOError("FITS save handler not installed")
_handler.save(im, fp, filename)
# --------------------------------------------------------------------
# Registry
Image.register_open(FITSStubImageFile.format, FITSStubImageFile, _accept)
Image.register_save(FITSStubImageFile.format, _save)
Image.register_extension(FITSStubImageFile.format, ".fit")
Image.register_extension(FITSStubImageFile.format, ".fits")
示例3: int
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
op.write("q %d 0 0 %d 0 0 cm /image Do Q\n" % (int(width * 72.0 / resolution), int(height * 72.0 / resolution)))
xref[5] = fp.tell()
_obj(fp, 5, Length = len(op.getvalue()))
fp.write("stream\n")
fp.write(op.getvalue())
fp.write("\nendstream\n")
_endobj(fp)
#
# trailer
startxref = fp.tell()
fp.write("xref\n0 %d\n0000000000 65535 f \n" % len(xref))
for x in xref[1:]:
fp.write("%010d 00000 n \n" % x)
fp.write("trailer\n<<\n/Size %d\n/Root 1 0 R\n>>\n" % len(xref))
fp.write("startxref\n%d\n%%%%EOF\n" % startxref)
fp.flush()
#
# --------------------------------------------------------------------
Image.register_save("PDF", _save)
Image.register_extension("PDF", ".pdf")
Image.register_mime("PDF", "application/pdf")
示例4: o32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
o32(im.size[1]) + # height
o16(1) + # planes
o16(bits) + # depth
o32(0) + # compression (0=uncompressed)
o32(image) + # size of bitmap
o32(1) + o32(1) + # resolution
o32(colors) + # colors used
o32(colors)) # colors important
fp.write("\000" * (header - 40)) # padding (for OS/2 format)
if im.mode == "1":
for i in (0, 255):
fp.write(chr(i) * 4)
elif im.mode == "L":
for i in range(256):
fp.write(chr(i) * 4)
elif im.mode == "P":
fp.write(im.im.getpalette("RGB", "BGRX"))
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, stride, -1))])
#
# --------------------------------------------------------------------
# Registry
Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
Image.register_save(BmpImageFile.format, _save)
Image.register_extension(BmpImageFile.format, ".bmp")
示例5: len
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
# data orientation
stride = len(bits) * ((im.size[0]*bits[0]+7)/8)
ifd[ROWSPERSTRIP] = im.size[1]
ifd[STRIPBYTECOUNTS] = stride * im.size[1]
ifd[STRIPOFFSETS] = 0 # this is adjusted by IFD writer
ifd[COMPRESSION] = 1 # no compression
offset = ifd.save(fp)
ImageFile._save(im, fp, [
("raw", (0,0)+im.size, offset, (rawmode, stride, 1))
])
# -- helper for multi-page save --
if im.encoderinfo.has_key("_debug_multipage"):
#just to access o32 and o16 (using correct byte order)
im._debug_multipage = ifd
#
# --------------------------------------------------------------------
# Register
Image.register_open("TIFF", TiffImageFile, _accept)
Image.register_save("TIFF", _save)
Image.register_extension("TIFF", ".tif")
Image.register_extension("TIFF", ".tiff")
Image.register_mime("TIFF", "image/tiff")
示例6: chr
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
fp.write(
chr(10) + chr(version) + chr(1) + chr(bits) + o16(0) +
o16(0) + o16(im.size[0]-1) + o16(im.size[1]-1) + o16(dpi[0]) +
o16(dpi[1]) + chr(0)*24 + chr(255)*24 + chr(0) + chr(planes) +
o16(stride) + o16(1) + o16(screen[0]) + o16(screen[1]) +
chr(0)*54
)
assert fp.tell() == 128
ImageFile._save(im, fp, [("pcx", (0,0)+im.size, 0,
(rawmode, bits*planes))])
if im.mode == "P":
# colour palette
fp.write(chr(12))
fp.write(im.im.getpalette("RGB", "RGB")) # 768 bytes
elif im.mode == "L":
# greyscale palette
fp.write(chr(12))
for i in range(256):
fp.write(chr(i)*3)
# --------------------------------------------------------------------
# registry
Image.register_open("PCX", PcxImageFile, _accept)
Image.register_save("PCX", _save)
Image.register_extension("PCX", ".pcx")
示例7: _save
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
self.tile = [("xbm", (0, 0)+self.size, m.end(), None)]
def _save(im, fp, filename):
if im.mode != "1":
raise IOError, "cannot write mode %s as XBM" % im.mode
fp.write("#define im_width %d\n" % im.size[0])
fp.write("#define im_height %d\n" % im.size[1])
hotspot = im.encoderinfo.get("hotspot")
if hotspot:
fp.write("#define im_x_hot %d\n" % hotspot[0])
fp.write("#define im_y_hot %d\n" % hotspot[1])
fp.write("static char im_bits[] = {\n")
ImageFile._save(im, fp, [("xbm", (0,0)+im.size, 0, None)])
fp.write("};\n")
Image.register_open("XBM", XbmImageFile, _accept)
Image.register_save("XBM", _save)
Image.register_extension("XBM", ".xbm")
Image.register_mime("XBM", "image/xbm")
示例8: _save
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
# --------------------------------------------------------------------
def _save(im, fp, filename):
if im.mode == "1":
rawmode, head = "1;I", "P4"
elif im.mode == "L":
rawmode, head = "L", "P5"
elif im.mode == "RGB":
rawmode, head = "RGB", "P6"
elif im.mode == "RGBA":
rawmode, head = "RGB", "P6"
else:
raise IOError, "cannot write mode %s as PPM" % im.mode
fp.write(head + "\n%d %d\n" % im.size)
if head != "P4":
fp.write("255\n")
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, 1))])
# ALTERNATIVE: save via builtin debug function
# im._dump(filename)
#
# --------------------------------------------------------------------
Image.register_open("PPM", PpmImageFile, _accept)
Image.register_save("PPM", _save)
Image.register_extension("PPM", ".pbm")
Image.register_extension("PPM", ".pgm")
Image.register_extension("PPM", ".ppm")
示例9: _accept
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
if not _accept(self.fp.read(8)):
raise SyntaxError("Not a BUFR file")
self.fp.seek(offset)
# make something up
self.mode = "F"
self.size = 1, 1
loader = self._load()
if loader:
loader.open(self)
def _load(self):
return _handler
def _save(im, fp, filename):
if _handler is None or not hasattr("_handler", "save"):
raise IOError("BUFR save handler not installed")
_handler.save(im, fp, filename)
# --------------------------------------------------------------------
# Registry
Image.register_open(BufrStubImageFile.format, BufrStubImageFile, _accept)
Image.register_save(BufrStubImageFile.format, _save)
Image.register_extension(BufrStubImageFile.format, ".bufr")
示例10: i16
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
# create MSP header
header = [0] * 16
header[0], header[1] = i16("Da"), i16("nM") # version 1
header[2], header[3] = im.size
header[4], header[5] = 1, 1
header[6], header[7] = 1, 1
header[8], header[9] = im.size
sum = 0
for h in header:
sum = sum ^ h
header[12] = sum # FIXME: is this the right field?
# header
for h in header:
fp.write(o16(h))
# image body
ImageFile._save(im, fp, [("raw", (0, 0) + im.size, 32, ("1", 0, 1))])
#
# registry
Image.register_open("MSP", MspImageFile, _accept)
Image.register_save("MSP", _save)
Image.register_extension("MSP", ".msp")
示例11: append
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
pass
def append(self, chunk):
self.data.append(chunk)
def append(fp, cid, *data):
data = string.join(data, "")
hi, lo = Image.core.crc32(data, Image.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
Image.register_open("PNG", PngImageFile, _accept)
Image.register_save("PNG", _save)
Image.register_extension("PNG", ".png")
Image.register_mime("PNG", "image/png")
示例12: chr
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
orientation = im.info.get("orientation", -1)
if orientation > 0:
flags = flags | 0x20
fp.write("\000" +
chr(colormaptype) +
chr(imagetype) +
o16(colormapfirst) +
o16(colormaplength) +
chr(colormapentry) +
o16(0) +
o16(0) +
o16(im.size[0]) +
o16(im.size[1]) +
chr(bits) +
chr(flags))
if colormaptype:
fp.write(im.im.getpalette("RGB", "BGR"))
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, 0, orientation))])
#
# --------------------------------------------------------------------
# Registry
Image.register_open("TGA", TgaImageFile, _accept)
Image.register_save("TGA", _save)
Image.register_extension("TGA", ".tga")
示例13: SyntaxError
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
self.info["dpi"] = xdpi, ydpi
else:
raise SyntaxError("Unsupported file format")
self.mode = "RGB"
self.size = size
loader = self._load()
if loader:
loader.open(self)
def _load(self):
return _handler
def _save(im, fp, filename):
if _handler is None or not hasattr("_handler", "save"):
raise IOError("WMF save handler not installed")
_handler.save(im, fp, filename)
#
# --------------------------------------------------------------------
# Registry stuff
Image.register_open(WmfStubImageFile.format, WmfStubImageFile, _accept)
Image.register_save(WmfStubImageFile.format, _save)
Image.register_extension(WmfStubImageFile.format, ".wmf")
Image.register_extension(WmfStubImageFile.format, ".emf")
示例14: range
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
fp.write(o16b(offset))
fp.write(chr(transparent_index))
fp.write(chr(compression_type))
fp.write(o16b(0)) # reserved by Palm
# now write colormap if necessary
if colormapsize > 0:
fp.write(o16b(256))
for i in range(256):
fp.write(chr(i))
if colormapmode == 'RGB':
fp.write(chr(colormap[3 * i]) + chr(colormap[3 * i + 1]) + chr(colormap[3 * i + 2]))
elif colormapmode == 'RGBA':
fp.write(chr(colormap[4 * i]) + chr(colormap[4 * i + 1]) + chr(colormap[4 * i + 2]))
# now convert data to raw form
ImageFile._save(im, fp, [("raw", (0,0)+im.size, 0, (rawmode, rowbytes, 1))])
fp.flush()
#
# --------------------------------------------------------------------
Image.register_save("Palm", _save)
Image.register_extension("Palm", ".palm")
Image.register_mime("Palm", "image/palm")
示例15: _save_cjpeg
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_save [as 别名]
info.get("smooth", 0),
info.has_key("optimize"),
info.get("streamtype", 0),
dpi[0], dpi[1],
subsampling,
extra,
)
ImageFile._save(im, fp, [("jpeg", (0,0)+im.size, 0, rawmode)])
def _save_cjpeg(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
Image.register_open("JPEG", JpegImageFile, _accept)
Image.register_save("JPEG", _save)
Image.register_extension("JPEG", ".jfif")
Image.register_extension("JPEG", ".jpe")
Image.register_extension("JPEG", ".jpg")
Image.register_extension("JPEG", ".jpeg")
Image.register_mime("JPEG", "image/jpeg")