Пример #1
0
    def save_thumbnail(self, image_file):
        """Save the thumbnail for this image.  image_file should be a file-like
        object containing the full-sized image.
        """

        self.thumbnail_extension = util.get_image_extension(image_file)
        image_file.seek(0)
        self._save_original_thumbnail(image_file)
        for width, height in self.THUMBNAIL_SIZES:
            image_file.seek(0)
            self._make_thumbnail(image_file, width, height)
        self.save()
Пример #2
0
 def test_thumbnails_converted_to_jpeg(self):
     self.login_and_submit_url()
     self.submit(thumbnail_file=
                 open(test_data_path('thumbnail_square.png')))
     channel = self.get_last_channel()
     self.assertTrue(channel.thumbnail_exists())
     for size in channel.THUMBNAIL_SIZES:
         path = channel.thumb_path('%dx%d' % size)
         self.assertTrue(os.path.exists(path))
         self.assertEquals(os.path.splitext(path)[1], '.jpeg')
         self.assertEquals(util.get_image_extension(
                 file(path)), 'jpeg')
Пример #3
0
 def clean(self, value, initial):
     if not value:
         if self.required:
             raise forms.ValidationError(_('This field is required.'))
         return None
     try:
         ext = util.get_image_extension(value)
     except ValueError:
         raise forms.ValidationError(_('Not a valid image'))
     else:
         if not ext:
             raise forms.ValidationError(
                 _('Not an image in a format we support.'))
         return value
Пример #4
0
 def clean(self, value, initial):
     if not value:
         if self.required:
             raise forms.ValidationError(_('This field is required.'))
         return None
     try:
         ext = util.get_image_extension(value)
     except ValueError:
         raise forms.ValidationError(_('Not a valid image'))
     else:
         if not ext:
             raise forms.ValidationError(
                 _('Not an image in a format we support.'))
         return value
Пример #5
0
    def update_thumbnails(self, overwrite=False, sizes=None):
        """Recreate the thumbnails using the original data."""

        if self.thumbnail_extension is None:
            pattern = self.thumb_path('original')
            pattern = pattern.replace("missing.png", "%d.*" % self.id)
            matches = glob(pattern)
            if matches:
                self.thumbnail_extension = util.get_image_extension(
                    file(matches[0]))
                self.save()

        Thumbnailable.refresh_thumbnails(self, overwrite, sizes)
        for item in self.items.order_by('-id'):
            try:
                item.refresh_thumbnails(overwrite, sizes)
            except: pass
Пример #6
0
    def update_thumbnails(self, overwrite=False, sizes=None):
        """Recreate the thumbnails using the original data."""

        if self.thumbnail_extension is None:
            pattern = self.thumb_path('original')
            pattern = pattern.replace("missing.png", "%d.*" % self.id)
            matches = glob(pattern)
            if matches:
                self.thumbnail_extension = util.get_image_extension(
                    file(matches[0]))
                self.save()

        Thumbnailable.refresh_thumbnails(self, overwrite, sizes)
        for item in self.items.order_by('-id'):
            try:
                item.refresh_thumbnails(overwrite, sizes)
            except:
                pass