本文整理匯總了Python中PIL.Image.core方法的典型用法代碼示例。如果您正苦於以下問題:Python Image.core方法的具體用法?Python Image.core怎麽用?Python Image.core使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PIL.Image
的用法示例。
在下文中一共展示了Image.core方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _getdecoder
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def _getdecoder(mode, decoder_name, args, extra=()):
# tweak arguments
if args is None:
args = ()
elif not isinstance(args, tuple):
args = (args,)
try:
decoder = DECODERS[decoder_name]
except KeyError:
pass
else:
return decoder(mode, *args + extra)
try:
# get decoder
decoder = getattr(core, decoder_name + "_decoder")
except AttributeError:
raise OSError("decoder %s not available" % decoder_name)
return decoder(mode, *args + extra)
示例2: _getencoder
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def _getencoder(mode, encoder_name, args, extra=()):
# tweak arguments
if args is None:
args = ()
elif not isinstance(args, tuple):
args = (args,)
try:
encoder = ENCODERS[encoder_name]
except KeyError:
pass
else:
return encoder(mode, *args + extra)
try:
# get encoder
encoder = getattr(core, encoder_name + "_encoder")
except AttributeError:
raise OSError("encoder %s not available" % encoder_name)
return encoder(mode, *args + extra)
# --------------------------------------------------------------------
# Simple expression analyzer
示例3: _crop
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def _crop(self, im, box):
"""
Returns a rectangular region from the core image object im.
This is equivalent to calling im.crop((x0, y0, x1, y1)), but
includes additional sanity checks.
:param im: a core image object
:param box: The crop rectangle, as a (left, upper, right, lower)-tuple.
:returns: A core image object.
"""
x0, y0, x1, y1 = map(int, map(round, box))
absolute_values = (abs(x1 - x0), abs(y1 - y0))
_decompression_bomb_check(absolute_values)
return im.crop((x0, y0, x1, y1))
示例4: blend
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def blend(im1, im2, alpha):
"""
Creates a new image by interpolating between two input images, using
a constant alpha.::
out = image1 * (1.0 - alpha) + image2 * alpha
:param im1: The first image.
:param im2: The second image. Must have the same mode and size as
the first image.
:param alpha: The interpolation alpha factor. If alpha is 0.0, a
copy of the first image is returned. If alpha is 1.0, a copy of
the second image is returned. There are no restrictions on the
alpha value. If necessary, the result is clipped to fit into
the allowed output range.
:returns: An :py:class:`~PIL.Image.Image` object.
"""
im1.load()
im2.load()
return im1._new(core.blend(im1.im, im2.im, alpha))
示例5: handler
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def handler(data, context):
"""Handle request.
Args:
data (obj): the request data
context (Context): an object containing request and configuration details
Returns:
(bytes, string): data to return to client, (optional) response content type
"""
# use the imported library
print('pillow: {}\n{}'.format(PIL.__version__, dir(_imaging)))
processed_input = _process_input(data, context)
response = requests.post(context.rest_uri, data=processed_input)
return _process_output(response, context)
示例6: _getdecoder
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def _getdecoder(mode, decoder_name, args, extra=()):
# tweak arguments
if args is None:
args = ()
elif not isinstance(args, tuple):
args = (args,)
try:
decoder = DECODERS[decoder_name]
return decoder(mode, *args + extra)
except KeyError:
pass
try:
# get decoder
decoder = getattr(core, decoder_name + "_decoder")
return decoder(mode, *args + extra)
except AttributeError:
raise IOError("decoder %s not available" % decoder_name)
示例7: _getencoder
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def _getencoder(mode, encoder_name, args, extra=()):
# tweak arguments
if args is None:
args = ()
elif not isinstance(args, tuple):
args = (args,)
try:
encoder = ENCODERS[encoder_name]
return encoder(mode, *args + extra)
except KeyError:
pass
try:
# get encoder
encoder = getattr(core, encoder_name + "_encoder")
return encoder(mode, *args + extra)
except AttributeError:
raise IOError("encoder %s not available" % encoder_name)
# --------------------------------------------------------------------
# Simple expression analyzer
示例8: test_render_scale1
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_render_scale1(self):
# We need png support for these render test
codecs = dir(Image.core)
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
self.skipTest("zip/deflate support not available")
# Zero bounding box
image1_scale1 = Image.open(file1)
image1_scale1.load()
image1_scale1_compare = Image.open(file1_compare).convert("RGB")
image1_scale1_compare.load()
self.assert_image_similar(image1_scale1, image1_scale1_compare, 5)
# Non-Zero bounding box
image2_scale1 = Image.open(file2)
image2_scale1.load()
image2_scale1_compare = Image.open(file2_compare).convert("RGB")
image2_scale1_compare.load()
self.assert_image_similar(image2_scale1, image2_scale1_compare, 10)
示例9: test_render_scale2
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_render_scale2(self):
# We need png support for these render test
codecs = dir(Image.core)
if "zip_encoder" not in codecs or "zip_decoder" not in codecs:
self.skipTest("zip/deflate support not available")
# Zero bounding box
image1_scale2 = Image.open(file1)
image1_scale2.load(scale=2)
image1_scale2_compare = Image.open(file1_compare_scale2).convert("RGB")
image1_scale2_compare.load()
self.assert_image_similar(image1_scale2, image1_scale2_compare, 5)
# Non-Zero bounding box
image2_scale2 = Image.open(file2)
image2_scale2.load(scale=2)
image2_scale2_compare = Image.open(file2_compare_scale2).convert("RGB")
image2_scale2_compare.load()
self.assert_image_similar(image2_scale2, image2_scale2_compare, 10)
示例10: test_ifd_rational_save
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_ifd_rational_save(self):
methods = (True, False)
if 'libtiff_encoder' not in dir(Image.core):
methods = (False,)
for libtiff in methods:
TiffImagePlugin.WRITE_LIBTIFF = libtiff
im = hopper()
out = self.tempfile('temp.tiff')
res = IFDRational(301, 1)
im.save(out, dpi=(res, res), compression='raw')
reloaded = Image.open(out)
self.assertEqual(float(IFDRational(301, 1)),
float(reloaded.tag_v2[282]))
示例11: test_load_raw
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_load_raw(self):
# Test basic EMF open and rendering
im = Image.open('Tests/images/drawing.emf')
if hasattr(Image.core, "drawwmf"):
# Currently, support for WMF/EMF is Windows-only
im.load()
# Compare to reference rendering
imref = Image.open('Tests/images/drawing_emf_ref.png')
imref.load()
self.assert_image_similar(im, imref, 0)
# Test basic WMF open and rendering
im = Image.open('Tests/images/drawing.wmf')
if hasattr(Image.core, "drawwmf"):
# Currently, support for WMF/EMF is Windows-only
im.load()
# Compare to reference rendering
imref = Image.open('Tests/images/drawing_wmf_ref.png')
imref.load()
self.assert_image_similar(im, imref, 2.0)
示例12: test_gimp_tiff
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_gimp_tiff(self):
# Read TIFF JPEG images from GIMP [@PIL168]
codecs = dir(Image.core)
if "jpeg_decoder" not in codecs:
self.skipTest("jpeg support not available")
filename = "Tests/images/pil168.tif"
im = Image.open(filename)
self.assertEqual(im.mode, "RGB")
self.assertEqual(im.size, (256, 256))
self.assertEqual(
im.tile, [('jpeg', (0, 0, 256, 256), 0, ('RGB', 'jpeg', False))]
)
im.load()
self.assert_image_equal_tofile(im, "Tests/images/pil168.png")
示例13: test_split_open
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_split_open(self):
codecs = dir(Image.core)
if 'zip_encoder' in codecs:
test_file = self.tempfile("temp.png")
else:
test_file = self.tempfile("temp.pcx")
def split_open(mode):
hopper(mode).save(test_file)
im = Image.open(test_file)
return len(im.split())
self.assertEqual(split_open("1"), 1)
self.assertEqual(split_open("L"), 1)
self.assertEqual(split_open("P"), 1)
self.assertEqual(split_open("RGB"), 3)
if 'zip_encoder' in codecs:
self.assertEqual(split_open("RGBA"), 4)
示例14: test_leak_load
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def test_leak_load(self):
with open('Tests/images/hopper.png', 'rb') as f:
DATA = BytesIO(f.read(16 * 1024))
ImageFile.LOAD_TRUNCATED_IMAGES = True
with Image.open(DATA) as im:
im.load()
def core():
with Image.open(DATA) as im:
im.load()
try:
self._test_leak(core)
finally:
ImageFile.LOAD_TRUNCATED_IMAGES = False
示例15: close
# 需要導入模塊: from PIL import Image [as 別名]
# 或者: from PIL.Image import core [as 別名]
def close(self):
"""
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory.
The image data will be unusable afterward.
This function is only required to close images that have not
had their file read and closed by the
:py:meth:`~PIL.Image.Image.load` method. See
:ref:`file-handling` for more information.
"""
try:
if hasattr(self, "_close__fp"):
self._close__fp()
self.fp.close()
self.fp = None
except Exception as msg:
logger.debug("Error closing: %s", msg)
if getattr(self, "map", None):
self.map = None
# Instead of simply setting to None, we're setting up a
# deferred error that will better explain that the core image
# object is gone.
self.im = deferred_error(ValueError("Operation on closed image"))