本文整理汇总了Python中pgmagick.Image.isValid方法的典型用法代码示例。如果您正苦于以下问题:Python Image.isValid方法的具体用法?Python Image.isValid怎么用?Python Image.isValid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pgmagick.Image
的用法示例。
在下文中一共展示了Image.isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pgmagick_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import isValid [as 别名]
def pgmagick_image(source, **options):
"""
Try to open the source file using pgmagick, ignoring any errors.
"""
# Use a StringIO wrapper because if the source is an incomplete file like
# object, PIL may have problems with it. For example, some image types
# require tell and seek methods that are not present on all storage
# File objects.
# import ipdb; ipdb.set_trace()
if not source:
return
source.open() # If tried by a previous source_generator, will be closed
source = StringIO(source.read())
try:
blob = Blob(source.read())
image = Image(blob)
except Exception:
logger.exception("unable to read image to create thumbnail")
return
if not image.isValid():
return
return convertGMtoPIL(image)
示例2: is_valid_image
# 需要导入模块: from pgmagick import Image [as 别名]
# 或者: from pgmagick.Image import isValid [as 别名]
def is_valid_image(self, raw_data):
blob = Blob()
blob.update(raw_data)
im = Image(blob)
return im.isValid()