Beispiel #1
0
def save_persona_image(src, full_dst, **kw):
    """Creates a PNG of a Persona header/footer image."""
    log.info("[1@None] 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
Beispiel #2
0
def save_persona_image(src, full_dst, **kw):
    """Creates a PNG of a Persona header/footer image."""
    log.info('[1@None] 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
Beispiel #3
0
def save_persona_image(src, full_dst, **kw):
    """Creates a PNG of a Persona header/footer image."""
    log.info('[1@None] 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
Beispiel #4
0
    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))
Beispiel #5
0
    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))
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
def save_persona_image(src, dst, img_basename, **kw):
    """Creates a JPG of a Persona header/footer image."""
    log.info('[1@None] 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)
Beispiel #9
0
def save_persona_image(src, dst, img_basename, **kw):
    """Creates a JPG of a Persona header/footer image."""
    log.info('[1@None] 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)
Beispiel #10
0
    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()
Beispiel #11
0
 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()
Beispiel #12
0
 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()
Beispiel #13
0
    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()