本文整理汇总了Python中lib.pil.Image.register_open方法的典型用法代码示例。如果您正苦于以下问题:Python Image.register_open方法的具体用法?Python Image.register_open怎么用?Python Image.register_open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类lib.pil.Image
的用法示例。
在下文中一共展示了Image.register_open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: getiptcinfo
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
try:
try:
# fast
self.im = Image.core.open_ppm(outfile)
except:
# slightly slower
im = Image.open(outfile)
im.load()
self.im = im.im
finally:
try: os.unlink(outfile)
except: pass
Image.register_open("IPTC", IptcImageFile)
Image.register_extension("IPTC", ".iim")
##
# Get IPTC information from TIFF, JPEG, or IPTC file.
#
# @param im An image containing IPTC data.
# @return A dictionary containing IPTC information, or None if
# no IPTC information block was found.
def getiptcinfo(im):
import TiffImagePlugin, JpegImagePlugin
import StringIO
示例2: _accept
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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")
示例3: load_read
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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")
示例4: o32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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_open [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_open [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: i32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
s = self.fp.read(4)
if i32(s) != MAGIC:
raise SyntaxError, "not a DCX file"
# Component directory
self._offset = []
for i in range(1024):
offset = i32(self.fp.read(4))
if not offset:
break
self._offset.append(offset)
self.__fp = self.fp
self.seek(0)
def seek(self, frame):
if frame >= len(self._offset):
raise EOFError("attempt to seek outside DCX directory")
self.frame = frame
self.fp = self.__fp
self.fp.seek(self._offset[frame])
PcxImageFile._open(self)
def tell(self):
return self.frame
Image.register_open("DCX", DcxImageFile, _accept)
Image.register_extension("DCX", ".dcx")
示例8: i32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
self.mode, rawmode = "1", "1;I"
elif depth == 8:
self.mode = rawmode = "L"
elif depth == 24:
self.mode, rawmode = "RGB", "BGR"
else:
raise SyntaxError, "unsupported mode"
compression = i32(s[20:24])
if i32(s[24:28]) != 0:
length = i32(s[28:32])
offset = offset + length
self.palette = ImagePalette.raw("RGB;L", self.fp.read(length))
if self.mode == "L":
self.mode = rawmode = "P"
stride = (((self.size[0] * depth + 7) / 8) + 3) & (~3)
if compression == 1:
self.tile = [("raw", (0,0)+self.size, offset, (rawmode, stride))]
elif compression == 2:
self.tile = [("sun_rle", (0,0)+self.size, offset, rawmode)]
#
# registry
Image.register_open("SUN", SunImageFile, _accept)
Image.register_extension("SUN", ".ras")
示例9: MpegImageFile
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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")
示例10: line
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
if s != "P7 332":
raise SyntaxError, "not an XV thumbnail file"
# Skip to beginning of next line
self.fp.readline()
# skip info comments
while 1:
s = self.fp.readline()
if not s:
raise SyntaxError, "Unexpected EOF reading XV thumbnail file"
if s[0] != '#':
break
# parse header line (already read)
s = string.split(s.strip())
self.mode = "P"
self.size = int(s[0]), int(s[1])
self.palette = ImagePalette.raw("RGB", PALETTE)
self.tile = [
("raw", (0, 0)+self.size,
self.fp.tell(), (self.mode, 0, 1)
)]
# --------------------------------------------------------------------
Image.register_open("XVThumb", XVThumbImageFile)
示例11: i32
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
if frame != self.frame + 1:
raise ValueError, "cannot seek to frame %d" % frame
self.frame = frame
# move to next frame
self.fp = self.__fp
self.fp.seek(self.__offset)
s = self.fp.read(4)
if not s:
raise EOFError
framesize = i32(s)
self.decodermaxblock = framesize
self.tile = [("fli", (0,0)+self.size, self.__offset, None)]
self.__offset = self.__offset + framesize
def tell(self):
return self.frame
#
# registry
Image.register_open("FLI", FliImageFile, _accept)
Image.register_extension("FLI", ".fli")
Image.register_extension("FLI", ".flc")
示例12: chr
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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: len
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
# read key/value pair
# FIXME: dangerous, may read whole file
s = s + self.fp.readline()
if len(s) == 1 or len(s) > 100:
break
if s[0] == "*":
continue # comment
m = field.match(s)
if not m:
break
k, v = m.group(1,2)
if k == "width":
xsize = int(v)
self.size = xsize, ysize
elif k == "height":
ysize = int(v)
self.size = xsize, ysize
elif k == "pixel" and v == "n8":
self.mode = "L"
#
# --------------------------------------------------------------------
Image.register_open("IMT", ImtImageFile)
#
# no extension registered (".im" is simply too common)
示例14: SyntaxError
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [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")
示例15: _open
# 需要导入模块: from lib.pil import Image [as 别名]
# 或者: from lib.pil.Image import register_open [as 别名]
def _open(self):
# assuming a 4-byte magic label (FIXME: add "_accept" hook)
s = self.fp.read(4)
if s != "\200\350\000\000":
raise SyntaxError, "not a PIXAR file"
# read rest of header
s = s + self.fp.read(508)
self.size = i16(s[418:420]), i16(s[416:418])
# get channel/depth descriptions
mode = i16(s[424:426]), i16(s[426:428])
if mode == (14, 2):
self.mode = "RGB"
# FIXME: to be continued...
# create tile descriptor (assuming "dumped")
self.tile = [("raw", (0,0)+self.size, 1024, (self.mode, 0, 1))]
#
# --------------------------------------------------------------------
Image.register_open("PIXAR", PixarImageFile)
#
# FIXME: what's the standard extension?