Example #1
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()
Example #2
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()
Example #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
    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
Example #5
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
Example #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
Example #7
0
    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
Example #8
0
    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