コード例 #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
コード例 #2
0
ファイル: tasks.py プロジェクト: hadjango/addons-server
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
コード例 #3
0
    def validate_picture_upload(self, value):
        image_check = ImageCheck(value)

        if (value.content_type not in amo.IMG_TYPES
                or not image_check.is_image()):
            raise serializers.ValidationError(
                ugettext(u'Images must be either PNG or JPG.'))

        if image_check.is_animated():
            raise serializers.ValidationError(
                ugettext(u'Images cannot be animated.'))

        if value.size > settings.MAX_PHOTO_UPLOAD_SIZE:
            raise serializers.ValidationError(
                ugettext(u'Please use images smaller than %dMB.' %
                         (settings.MAX_PHOTO_UPLOAD_SIZE / 1024 / 1024)))
        return value
コード例 #4
0
    def validate_picture_upload(self, value):
        image_check = ImageCheck(value)

        if (value.content_type not in amo.IMG_TYPES or
                not image_check.is_image()):
            raise serializers.ValidationError(
                ugettext(u'Images must be either PNG or JPG.'))

        if image_check.is_animated():
            raise serializers.ValidationError(
                ugettext(u'Images cannot be animated.'))

        if value.size > settings.MAX_PHOTO_UPLOAD_SIZE:
            raise serializers.ValidationError(
                ugettext(u'Please use images smaller than %dMB.' %
                         (settings.MAX_PHOTO_UPLOAD_SIZE / 1024 / 1024 - 1)))
        return value
コード例 #5
0
ファイル: test_helpers.py プロジェクト: MayankR/addons-server
    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()
コード例 #6
0
    def clean_icon(self):
        icon = self.cleaned_data['icon']
        if not icon:
            return
        icon_check = ImageCheck(icon)
        if (icon.content_type not in amo.IMG_TYPES or
                not icon_check.is_image()):
            raise forms.ValidationError(
                ugettext('Icons must be either PNG or JPG.'))

        if icon_check.is_animated():
            raise forms.ValidationError(ugettext('Icons cannot be animated.'))

        if icon.size > settings.MAX_ICON_UPLOAD_SIZE:
            size_in_mb = settings.MAX_ICON_UPLOAD_SIZE / 1024 / 1024 - 1
            raise forms.ValidationError(
                ugettext('Please use images smaller than %dMB.') % size_in_mb)
        return icon
コード例 #7
0
ファイル: forms.py プロジェクト: vparfonov/addons-server
    def clean_icon(self):
        icon = self.cleaned_data['icon']
        if not icon:
            return
        icon_check = ImageCheck(icon)
        if (icon.content_type not in amo.IMG_TYPES
                or not icon_check.is_image()):
            raise forms.ValidationError(
                ugettext('Icons must be either PNG or JPG.'))

        if icon_check.is_animated():
            raise forms.ValidationError(ugettext('Icons cannot be animated.'))

        if icon.size > settings.MAX_ICON_UPLOAD_SIZE:
            size_in_mb = settings.MAX_ICON_UPLOAD_SIZE / 1024 / 1024 - 1
            raise forms.ValidationError(
                ugettext('Please use images smaller than %dMB.') % size_in_mb)
        return icon
コード例 #8
0
ファイル: forms.py プロジェクト: piyushmittal25/addons-server
    def clean_photo(self):
        photo = self.cleaned_data['photo']

        if not photo:
            return

        image_check = ImageCheck(photo)
        if (photo.content_type not in amo.IMG_TYPES or
                not image_check.is_image()):
            raise forms.ValidationError(
                ugettext('Images must be either PNG or JPG.'))

        if image_check.is_animated():
            raise forms.ValidationError(ugettext('Images cannot be animated.'))

        if photo.size > settings.MAX_PHOTO_UPLOAD_SIZE:
            msg = ugettext('Please use images smaller than %dMB.')
            size_in_mb = settings.MAX_PHOTO_UPLOAD_SIZE / 1024 / 1024
            raise forms.ValidationError(msg % size_in_mb)

        return photo
コード例 #9
0
ファイル: forms.py プロジェクト: waf/addons-server
    def clean_photo(self):
        photo = self.cleaned_data['photo']

        if not photo:
            return

        image_check = ImageCheck(photo)
        if (photo.content_type not in amo.IMG_TYPES
                or not image_check.is_image()):
            raise forms.ValidationError(
                ugettext('Images must be either PNG or JPG.'))

        if image_check.is_animated():
            raise forms.ValidationError(ugettext('Images cannot be animated.'))

        if photo.size > settings.MAX_PHOTO_UPLOAD_SIZE:
            msg = ugettext('Please use images smaller than %dMB.')
            size_in_mb = settings.MAX_PHOTO_UPLOAD_SIZE / 1024 / 1024
            raise forms.ValidationError(msg % size_in_mb)

        return photo
コード例 #10
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()
コード例 #11
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()
コード例 #12
0
ファイル: test_helpers.py プロジェクト: MayankR/addons-server
 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()