本文整理匯總了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)