本文整理汇总了Python中PIL.Image.MAX_IMAGE_PIXELS属性的典型用法代码示例。如果您正苦于以下问题:Python Image.MAX_IMAGE_PIXELS属性的具体用法?Python Image.MAX_IMAGE_PIXELS怎么用?Python Image.MAX_IMAGE_PIXELS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类PIL.Image
的用法示例。
在下文中一共展示了Image.MAX_IMAGE_PIXELS属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_overflow
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def test_overflow(self):
# There is the potential to overflow comparisons in map.c
# if there are > SIZE_MAX bytes in the image or if
# the file encodes an offset that makes
# (offset + size(bytes)) > SIZE_MAX
# Note that this image triggers the decompression bomb warning:
max_pixels = Image.MAX_IMAGE_PIXELS
Image.MAX_IMAGE_PIXELS = None
# This image hits the offset test.
im = Image.open('Tests/images/l2rgb_read.bmp')
with self.assertRaises((ValueError, MemoryError, IOError)):
im.load()
Image.MAX_IMAGE_PIXELS = max_pixels
示例2: tearDown
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def tearDown(self):
Image.MAX_IMAGE_PIXELS = ORIGINAL_LIMIT
示例3: test_no_warning_no_limit
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def test_no_warning_no_limit(self):
# Arrange
# Turn limit off
Image.MAX_IMAGE_PIXELS = None
self.assertIsNone(Image.MAX_IMAGE_PIXELS)
# Act / Assert
# Implicit assert: no warning.
# A warning would cause a failure.
Image.open(TEST_FILE)
示例4: test_warning
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def test_warning(self):
# Set limit to trigger warning on the test file
Image.MAX_IMAGE_PIXELS = 128 * 128 - 1
self.assertEqual(Image.MAX_IMAGE_PIXELS, 128 * 128 - 1)
self.assert_warning(Image.DecompressionBombWarning,
Image.open, TEST_FILE)
示例5: test_exception
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def test_exception(self):
# Set limit to trigger exception on the test file
Image.MAX_IMAGE_PIXELS = 64 * 128 - 1
self.assertEqual(Image.MAX_IMAGE_PIXELS, 64 * 128 - 1)
self.assertRaises(Image.DecompressionBombError,
lambda: Image.open(TEST_FILE))
示例6: setUp
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def setUp(self):
self.src = hopper()
Image.MAX_IMAGE_PIXELS = self.src.height * self.src.width * 4 - 1
示例7: make_image_versions
# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MAX_IMAGE_PIXELS [as 别名]
def make_image_versions(self, src):
""" Copies a directory structure
and makes thumbnail and preview files
"""
src_dir = self.set_check_directory(src)
print('Working on :' + src_dir)
new_root_dir = self.set_check_directory('copy-' + src)
new_dirs = [self.full_dir,
self.preview_dir,
self.thumbs_dir]
for new_dir in new_dirs:
dst_dir = new_root_dir + new_dir
if not os.path.exists(dst_dir):
for dirpath, dirnames, filenames in os.walk(src_dir):
trim_dirpath = dirpath[len(src_dir):]
if len(trim_dirpath) > 1:
if trim_dirpath[0] == '/' or trim_dirpath[0] == '\\':
trim_dirpath = dirpath[1+len(src_dir):]
"""
act_dir = os.path.join(dst_dir,
dirpath[1+len(src_dir):])
"""
act_dir = os.path.join(dst_dir, trim_dirpath)
os.mkdir(act_dir)
for filename in filenames:
src_file = os.path.join(dirpath, filename)
print('Working on src_file: ' + src_file)
if self.force_dashes:
# make sure the new filenames have dashes, not spaces or underscores
filename = filename.replace(' ', '-')
filename = filename.replace('_', '-')
if new_dir == self.full_dir:
new_file = os.path.join(act_dir, filename)
# its the full size file, just copy it without modification
print('Copy full: ' + new_file)
shutil.copy2(src_file, new_file)
else:
# we need to modify the image
file_no_ext = os.path.splitext(filename)[0]
filename_jpg = file_no_ext + '.jpg'
new_file = os.path.join(act_dir, filename_jpg)
try:
Image.MAX_IMAGE_PIXELS = self.max_image_size
im = Image.open(src_file)
except:
print('Cannot use as image: ' + src_file)
im = False
if im is not False:
ratio = 1 # default to same size
if new_dir == self.preview_dir:
print('Make preview: ' + new_file)
self.make_preview_file(src_file, new_file)
elif new_dir == self.thumbs_dir:
print('Make thumbnail: ' + new_file)
self.make_thumbnail_file(src_file, new_file)