我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用PIL.Image._decompression_bomb_check()。
def seek(self, frame): "Select a given frame as current image" self._seek(max(frame, 0)) # Questionable backwards compatibility. # Create a new core image object on second and # subsequent frames in the image. Image may be # different size/mode. Image._decompression_bomb_check(self.size) self.im = Image.core.new(self.mode, self.size)
def _open(self): header_size = i32(self.fp.read(4)) version = i32(self.fp.read(4)) if header_size < 20: raise SyntaxError("not a GIMP brush") if version not in (1, 2): raise SyntaxError("Unsupported GIMP brush version: %s" % version) width = i32(self.fp.read(4)) height = i32(self.fp.read(4)) color_depth = i32(self.fp.read(4)) if width <= 0 or height <= 0: raise SyntaxError("not a GIMP brush") if color_depth not in (1, 4): raise SyntaxError("Unsupported GIMP brush color depth: %s" % color_depth) if version == 1: comment_length = header_size-20 else: comment_length = header_size-28 magic_number = self.fp.read(4) if magic_number != b'GIMP': raise SyntaxError("not a GIMP brush, bad magic number") self.info['spacing'] = i32(self.fp.read(4)) comment = self.fp.read(comment_length)[:-1] if color_depth == 1: self.mode = "L" else: self.mode = 'RGBA' self.size = width, height self.info["comment"] = comment # Image might not be small Image._decompression_bomb_check(self.size) # Data is an uncompressed block of w * h * bytes/pixel self._data_size = width * height * color_depth
def _open(self): header_size = i32(self.fp.read(4)) version = i32(self.fp.read(4)) if header_size < 20: raise SyntaxError("not a GIMP brush") if version not in (1,2): raise SyntaxError("Unsupported GIMP brush version: %s" %version) width = i32(self.fp.read(4)) height = i32(self.fp.read(4)) color_depth = i32(self.fp.read(4)) if width <= 0 or height <= 0: raise SyntaxError("not a GIMP brush") if color_depth not in (1,4): raise SyntaxError("Unsupported GMP brush color depth: %s" %color_depth) if version == 1: comment_length = header_size-20 else: comment_length = header_size-28 magic_number = self.fp.read(4) if magic_number != b'GIMP': raise SyntaxError("not a GIMP brush, bad magic number") self.info['spacing'] = i32(self.fp.read(4)) comment = self.fp.read(comment_length)[:-1] if color_depth == 1: self.mode = "L" else: self.mode = 'RGBA' self.size = width, height self.info["comment"] = comment # Image might not be small Image._decompression_bomb_check(self.size) # Data is an uncompressed block of w * h * bytes/pixel self._data_size = width * height * color_depth
def open(filename): """ Load texture from a Quake2 WAL texture file. By default, a Quake2 standard palette is attached to the texture. To override the palette, use the <b>putpalette</b> method. :param filename: WAL file name, or an opened file handle. :returns: An image instance. """ # FIXME: modify to return a WalImageFile instance instead of # plain Image object ? def imopen(fp): # read header fields header = fp.read(32+24+32+12) size = i32(header, 32), i32(header, 36) offset = i32(header, 40) # load pixel data fp.seek(offset) Image._decompression_bomb_check(size) im = Image.frombytes("P", size, fp.read(size[0] * size[1])) im.putpalette(quake2palette) im.format = "WAL" im.format_description = "Quake2 Texture" # strings are null-terminated im.info["name"] = header[:32].split(b"\0", 1)[0] next_name = header[56:56+32].split(b"\0", 1)[0] if next_name: im.info["next_name"] = next_name return im if hasattr(filename, "read"): return imopen(filename) else: with builtins.open(filename, "rb") as fp: return imopen(fp)