Example #1
0
 def test_save_thumbnail_as_jpg(self):
     key = 'test/giftest/exifTest.jpg'
     url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key)
     thumbnail = Thumbnail(user=self.user_test,
                           thumbnail_file=settings.THUMBNAIL_DEFAULT,
                           thumbnail_sizes={})
     thumbnail.save()
     thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail)
     test_cases = set(thumbnail.thumbnail_sizes.values())
     for t in test_cases:
         Image.open(urllib.urlretrieve(t)[0])
Example #2
0
 def test_save_tif_as_jpeg_thumbnail(self):
     key = 'test/imagetests/lenna.tif'
     url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key)
     thumbnail = Thumbnail(user=self.user_test,
                           thumbnail_file=settings.THUMBNAIL_DEFAULT,
                           thumbnail_sizes={})
     thumbnail.save()
     thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail)
     thumbnail_formats = [
         Image.open(urllib.urlretrieve(thumbnail_url)[0]).format
         for thumbnail_url in thumbnail.thumbnail_sizes.values()
     ]
     self.assertTrue(
         all(f == 'JPEG' for f in thumbnail_formats),
         msg='All thumbnails of a TIF file must be of format JPEG')
Example #3
0
 def test_resize_gif(self):
     key = 'test/giftest/ERuXtjY.gif'
     url = 'https://s3-us-west-2.amazonaws.com/ascribe0/{}'.format(key)
     thumbnail = Thumbnail(user=self.user_test,
                           thumbnail_file=settings.THUMBNAIL_DEFAULT,
                           thumbnail_sizes={})
     thumbnail.save()
     thumbnail = Thumbnail.thumbnail_from_url(url, key, thumbnail)
     test_cases = set(thumbnail.thumbnail_sizes.values())
     for t in test_cases:
         try:
             output_image = Image.open(urllib.urlretrieve(t)[0])
         except Exception, e:
             # Lol
             print 'Exception ... '
             raise AssertionError(e.args)
         try:
             output_image.seek(1)
         except:
             raise AssertionError('Gif is not animated')
Example #4
0
#thumbs = Thumbnail.objects.filter(user__isnull=False, thumbnail_file__contains='.gif').exclude(user__pk__in=test_users)
thumb_ids = [t.id for t in thumbs]

#pieces = [p.id for p in Piece.objects.filter(thumbnail__in=thumb_ids)]

#Piece.objects.filter(id__in=pieces).update(thumbnail_id='NULL')
Thumbnail.objects.filter(id__in=thumb_ids).delete()

new_thumbnails = []
bad_thumbnails = []

for g in gifs:
    basename = g.associated_key('thumbnail', '', unique=False)
    try:
        new_thumbnails.append(
            Thumbnail.thumbnail_from_url(g.user, g.url, basename))
    except Exception as e:
        print sys.exc_info()
        print traceback.print_exc()
        bad_thumbnails.append([sys.exc_info(), g])

print 'new thumbnails'
print new_thumbnails
print 'bad ones .. '
print bad_thumbnails

#for n in new_thumbnails:
#    piece_name = n.thumbnail_file.split('/')[2]
#    for g in gifs:
#        if piece_name in g.digital_work_file:
#            Piece.objects.filter(digital_work_id=g.id).update(thumbnail_id=n.id)