本文整理汇总了Python中amo.utils.ImageCheck类的典型用法代码示例。如果您正苦于以下问题:Python ImageCheck类的具体用法?Python ImageCheck怎么用?Python ImageCheck使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ImageCheck类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save_persona_image
def save_persona_image(src, full_dst, **kw):
"""Creates a PNG of a Persona header/footer image."""
log.info("[[email protected]] Saving persona image: %s" % full_dst)
img = ImageCheck(storage.open(src))
if not img.is_image():
log.error("Not an image: %s" % src, exc_info=True)
return
with storage.open(src, "rb") as fp:
i = Image.open(fp)
with storage.open(full_dst, "wb") as fp:
i.save(fp, "png")
return True
示例2: check_icons
def check_icons(self, webapp):
manifest = webapp.get_manifest_json()
biggest = max([int(size) for size in manifest["icons"]])
icon_dir = webapp.get_icon_dir()
for size in amo.ADDON_ICON_SIZES:
if not size <= biggest:
continue
icon_path = os.path.join(icon_dir, "%s-%s.png" % (str(webapp.id), size))
with open(icon_path, "r") as img:
checker = ImageCheck(img)
assert checker.is_image()
eq_(checker.img.size, (size, size))
示例3: check_icons
def check_icons(self, webapp, file_obj=None):
manifest = webapp.get_manifest_json(file_obj)
biggest = max([int(size) for size in manifest['icons']])
icon_dir = webapp.get_icon_dir()
for size in amo.APP_ICON_SIZES:
if not size <= biggest:
continue
icon_path = os.path.join(icon_dir, '%s-%s.png'
% (str(webapp.id), size))
with open(icon_path, 'r') as img:
checker = ImageCheck(img)
assert checker.is_image()
eq_(checker.img.size, (size, size))
示例4: _check_image
def _check_image(im_path, abs_url):
valid = True
img_format = ''
with open(im_path, 'rb') as fp:
im = ImageCheck(fp)
if not im.is_image():
valid = False
log.error('image at %s is not an image' % abs_url)
if im.is_animated():
valid = False
log.error('image at %s is animated' % abs_url)
if valid:
img_format = im.img.format
return valid, img_format
示例5: save_persona_image
def save_persona_image(src, dst, img_basename, **kw):
"""Creates a JPG of a Persona header/footer image."""
log.info('[[email protected]] Saving persona image: %s' % dst)
img = ImageCheck(storage.open(src))
if not img.is_image():
log.error('Not an image: %s' % src, exc_info=True)
return
try:
with storage.open(src) as fp:
i = Image.open(fp)
with storage.open(os.path.join(dst, img_basename), 'wb') as fp:
i.save(fp)
return True
except Exception, e:
log.error('Error saving persona image: %s' % e)
示例6: test_animated_images
def test_animated_images(self):
img = ImageCheck(open(get_image_path('animated.png')))
assert img.is_animated()
img = ImageCheck(open(get_image_path('non-animated.png')))
assert not img.is_animated()
img = ImageCheck(open(get_image_path('animated.gif')))
assert img.is_animated()
img = ImageCheck(open(get_image_path('non-animated.gif')))
assert not img.is_animated()
示例7: test_junk
def test_junk(self):
img = ImageCheck(open(__file__, 'rb'))
assert not img.is_image()
img = ImageCheck(open(get_image_path('non-animated.gif')))
assert img.is_image()