本文整理汇总了Python中PIL.ImageFile.MAXBLOCK属性的典型用法代码示例。如果您正苦于以下问题:Python ImageFile.MAXBLOCK属性的具体用法?Python ImageFile.MAXBLOCK怎么用?Python ImageFile.MAXBLOCK使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类PIL.ImageFile
的用法示例。
在下文中一共展示了ImageFile.MAXBLOCK属性的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: JpegString
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def JpegString(image, jpeg_quality=90):
"""Returns given PIL.Image instance as jpeg string.
Args:
image: A PIL image.
jpeg_quality: The image quality, on a scale from 1 (worst) to 95 (best).
Returns:
a jpeg_string.
"""
# This fix to PIL makes sure that we don't get an error when saving large
# jpeg files. This is a workaround for a bug in PIL. The value should be
# substantially larger than the size of the image being saved.
ImageFile.MAXBLOCK = 640 * 512 * 64
output_jpeg = StringIO()
image.save(output_jpeg, 'jpeg', quality=jpeg_quality, optimize=True)
return output_jpeg.getvalue()
示例2: test_icc_big
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def test_icc_big(self):
# Make sure that the "extra" support handles large blocks
def test(n):
# The ICC APP marker can store 65519 bytes per marker, so
# using a 4-byte test code should allow us to detect out of
# order issues.
icc_profile = (b"Test"*int(n/4+1))[:n]
self.assertEqual(len(icc_profile), n) # sanity
im1 = self.roundtrip(hopper(), icc_profile=icc_profile)
self.assertEqual(im1.info.get("icc_profile"), icc_profile or None)
test(0)
test(1)
test(3)
test(4)
test(5)
test(65533-14) # full JPEG marker block
test(65533-14+1) # full block plus one byte
test(ImageFile.MAXBLOCK) # full buffer block
test(ImageFile.MAXBLOCK+1) # full buffer block plus one byte
test(ImageFile.MAXBLOCK*4+3) # large block
示例3: jpeg_string
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def jpeg_string(image, jpeg_quality = 90):
"""Returns given PIL.Image instance as jpeg string.
Args:
image: A PIL image.
jpeg_quality: The image quality, on a scale from 1 (worst) to 95 (best).
Returns:
a jpeg_string.
"""
# This fix to PIL makes sure that we don't get an error when saving large
# jpeg files. This is a workaround for a bug in PIL. The value should be
# substantially larger than the size of the image being saved.
ImageFile.MAXBLOCK = 640 * 512 * 64
output_jpeg = io.BytesIO()
image.save(output_jpeg, 'jpeg', quality=jpeg_quality, optimize=True)
return output_jpeg.getvalue()
示例4: _test_buffer_overflow
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def _test_buffer_overflow(self, im, size=1024):
_last = ImageFile.MAXBLOCK
ImageFile.MAXBLOCK = size
try:
self._roundtrip(im)
finally:
ImageFile.MAXBLOCK = _last
示例5: test_large_icc_meta
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def test_large_icc_meta(self):
# https://github.com/python-pillow/Pillow/issues/148
# Sometimes the meta data on the icc_profile block is bigger than
# Image.MAXBLOCK or the image size.
im = Image.open('Tests/images/icc_profile_big.jpg')
f = self.tempfile("temp.jpg")
icc_profile = im.info["icc_profile"]
# Should not raise IOError for image with icc larger than image size.
im.save(f, format='JPEG', progressive=True, quality=95,
icc_profile=icc_profile, optimize=True)
示例6: test_optimize_large_buffer
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def test_optimize_large_buffer(self):
# https://github.com/python-pillow/Pillow/issues/148
f = self.tempfile('temp.jpg')
# this requires ~ 1.5x Image.MAXBLOCK
im = Image.new("RGB", (4096, 4096), 0xff3333)
im.save(f, format="JPEG", optimize=True)
示例7: test_progressive_large_buffer
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def test_progressive_large_buffer(self):
f = self.tempfile('temp.jpg')
# this requires ~ 1.5x Image.MAXBLOCK
im = Image.new("RGB", (4096, 4096), 0xff3333)
im.save(f, format="JPEG", progressive=True)
示例8: pil_save
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def pil_save(filename, pixels, width, height):
from PIL import Image, ImageFile
buffer_len = (width * 3 + 3) & -4
img = Image.frombuffer('RGB', (width, height), pixels, 'raw', 'BGR', buffer_len, 1)
ImageFile.MAXBLOCK = width * height
img=img.transpose(Image.FLIP_TOP_BOTTOM)
img.save(filename, quality=95, optimize=True, progressive=True)
logging.info('webcam snap saved to %s'%filename)
示例9: pil_save
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def pil_save(filename, pixels, width, height):
from PIL import Image, ImageFile
buffer_len = (width * 3 + 3) & -4
img = Image.frombuffer('RGB', (width, height), pixels, 'raw', 'BGR', buffer_len, 1)
ImageFile.MAXBLOCK = width * height
img=img.transpose(Image.FLIP_TOP_BOTTOM)
img.save(filename, quality=95, optimize=True, progressive=True)
示例10: pil_save
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def pil_save(filename, pixels, width, height):
from PIL import Image, ImageFile
buffer_len = (width * 3 + 3) & -4
img = Image.frombuffer('RGB', (width, height), pixels, 'raw', 'BGR', buffer_len, 1)
ImageFile.MAXBLOCK = width * height
img=img.transpose(Image.FLIP_TOP_BOTTOM)
img.save(filename, quality=95, optimize=True, progressive=True)
logging.info('Screenshot saved to %s'%filename)
示例11: is_big_png_photo
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def is_big_png_photo(src_path: str) -> bool:
"""Try to determine if a given image if a big photo in PNG format
Expects a path to a PNG image file. Returns True if the image is a PNG
with an area bigger than MIN_BIG_IMG_AREA pixels that when resized to 1600
pixels (wide or high) converts to a JPEG bigger than MIN_BIG_IMG_SIZE.
Returns False otherwise.
Inspired by an idea first presented by Stephen Arthur
(https://engineeringblog.yelp.com/2017/06/making-photos-smaller.html)
"""
img = Image.open(src_path)
orig_format = img.format
orig_mode = img.mode
if orig_format != 'PNG' or orig_mode in ['P', 'L', 'LA']:
return False
w, h = img.size
if (w * h) >= MIN_BIG_IMG_AREA:
unique_colors = {img.getpixel((x, y)) for x in range(w) for y in range(h)}
if len(unique_colors) > 2 ** 16:
img = img.convert("RGB")
if w > h:
img, status = downsize_img(img, 1600, 0)
else:
img, status = downsize_img(img, 0, 1600)
tempfile = BytesIO()
try:
img.save(tempfile, quality=80, format="JPEG")
except IOError:
ImageFile.MAXBLOCK = img.size[0] * img.size[1]
img.save(tempfile, quality=80, format="JPEG")
final_size = tempfile.getbuffer().nbytes
return final_size > MIN_BIG_IMG_SIZE
return False
示例12: drawImageColoredTriangles
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def drawImageColoredTriangles(triangles, filename, origIm, multiplier):
(sizeX, sizeY) = origIm.size
im = Image.new('RGB', (sizeX*multiplier, sizeY*multiplier))
draw = ImageDraw.Draw(im)
start = time.clock()
for t in triangles:
(r,g,b) = getTriangleColor(t, origIm)
p0 = tuple(map(lambda x:x*multiplier, t[0]))
p1 = tuple(map(lambda x:x*multiplier, t[1]))
p2 = tuple(map(lambda x:x*multiplier, t[2]))
drawT = (p0, p1, p2)
draw.polygon(drawT, fill=(r,g,b,255))
im = brightenImage(im, 3.0)
ImageFile.MAXBLOCK = im.size[0] * im.size[1]
im.save(filename, "JPEG", quality=100, optimize=True, progressive=True)
示例13: drawImageColoredVoronoi
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def drawImageColoredVoronoi(polygons, filename, origIm, multiplier):
start = time.clock()
(sizeX, sizeY) = origIm.size
im = Image.new('RGB', (sizeX*multiplier, sizeY*multiplier))
draw = ImageDraw.Draw(im)
for pol in polygons:
if len(pol) < 2:
continue
(r,g,b) = getPolygonColor(pol, origIm)
newPol = map(lambda x: (x[0] * multiplier, x[1]*multiplier), pol)
draw.polygon(newPol, fill=(r,g,b,255))
im = brightenImage(im, 3.0)
ImageFile.MAXBLOCK = im.size[0] * im.size[1]
im.save(filename, "JPEG", quality=100, optimize=True, progressive=True)
print "Voronoi zeichnen: %.2fs" % (time.clock()-start)
示例14: save_image_with_overlay
# 需要导入模块: from PIL import ImageFile [as 别名]
# 或者: from PIL.ImageFile import MAXBLOCK [as 别名]
def save_image_with_overlay(im, name):
output_filename = name + "_out.jpg"
ImageFile.MAXBLOCK = 2 ** 20
im.save(output_filename, "JPEG", quality=80, optimize=True, progressive=True)