本文整理汇总了Python中lib.pil.Image.register_mime方法的典型用法代码示例。如果您正苦于以下问题:Python Image.register_mime方法的具体用法?Python Image.register_mime怎么用?Python Image.register_mime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.pil.Image
的用法示例。
在下文中一共展示了Image.register_mime方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_read
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [as 别名]
self.mode = "P"
self.palette = ImagePalette.raw("RGB", string.join(palette, ""))
self.tile = [("raw", (0, 0)+self.size, self.fp.tell(), ("P", 0, 1))]
def load_read(self, bytes):
#
# load all image data in one chunk
xsize, ysize = self.size
s = [None] * ysize
for i in range(ysize):
s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)
self.fp = None
return string.join(s, "")
#
# Registry
Image.register_open("XPM", XpmImageFile, _accept)
Image.register_extension("XPM", ".xpm")
Image.register_mime("XPM", "image/xpm")
示例2: int
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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")
示例3: _save_cjpeg
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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")
示例4: _save
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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")
示例5: len
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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: o16
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [as 别名]
o16(offset[0]) + # offset
o16(offset[1]) +
o16(im.size[0]) + # size
o16(im.size[1]) +
chr(0) + # flags
chr(8)) # bits
ImageFile._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
Image.register_open(GifImageFile.format, GifImageFile, _accept)
Image.register_save(GifImageFile.format, _save)
Image.register_extension(GifImageFile.format, ".gif")
Image.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)
示例7: append
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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")
示例8: MpegImageFile
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [as 别名]
##
# Image plugin for MPEG streams. This plugin can identify a stream,
# but it cannot read it.
class MpegImageFile(ImageFile.ImageFile):
format = "MPEG"
format_description = "MPEG"
def _open(self):
s = BitStream(self.fp)
if s.read(32) != 0x1B3:
raise SyntaxError, "not an MPEG file"
self.mode = "RGB"
self.size = s.read(12), s.read(12)
# --------------------------------------------------------------------
# Registry stuff
Image.register_open("MPEG", MpegImageFile)
Image.register_extension("MPEG", ".mpg")
Image.register_extension("MPEG", ".mpeg")
Image.register_mime("MPEG", "video/mpeg")
示例9: range
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [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")
示例10: tell
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_mime [as 别名]
if Image.DEBUG:
print cid, bytes, "(unknown)"
s = self.fp.read(bytes)
self.arg.crc(cid, s)
self.fp.read(4) # ship extra CRC
def tell(self):
return 0
def verify(self):
"Verify ARG file"
# back up to first chunk
self.fp.seek(8)
self.arg.verify(self)
self.arg.close()
self.fp = None
#
# --------------------------------------------------------------------
Image.register_open("ARG", ArgImageFile, _accept)
Image.register_extension("ARG", ".arg")
Image.register_mime("ARG", "video/x-arg")