Esempio n. 1
0
 def test_adjust__unequal(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(width=50, height=40)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 40))
     expected = Image.open(self._data_path('50x40_fill.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 2
0
 def test_adjust__max_width__smaller(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(height=100, max_width=50)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 100))
     expected = Image.open(self._data_path('50x100_crop.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 3
0
 def test_adjust__max_width(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(height=50, max_width=200)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 50))
     expected = Image.open(self._data_path('50x50_fit.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 4
0
 def test_adjust__unequal(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(width=50, height=40)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 40))
     expected = Image.open(self._data_path('50x40_fill.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 5
0
 def test_adjust__max_width(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(height=50, max_width=200)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 50))
     expected = Image.open(self._data_path('50x50_fit.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 6
0
 def test_adjust__max_width__smaller(self):
     im = Image.open(self._data_path('100x100.png'))
     fill = Fill(height=100, max_width=50)
     adjusted = fill.adjust(im)
     self.assertEqual(adjusted.size, (50, 100))
     expected = Image.open(self._data_path('50x100_crop.png'))
     self.assertImageEqual(adjusted, expected)
Esempio n. 7
0
 def _bulk_adjusted_items(self, items):
     if self.feed_type is JSONGenerator:
         sizes = THUMBNAIL_SIZES
     else:
         sizes = THUMBNAIL_SIZES[:2]
     for size in sizes:
         helper = AdjustmentHelper(items,
                                   [Fill(width=size[0], height=size[1])],
                                   "thumbnail")
         for item, info_dict in helper.info_dicts():
             # Set a private attribute so we can retrieve this later.
             if not hasattr(item, '_adjusted'):
                 item._adjusted = {}
             item._adjusted[size] = info_dict
     # set the default adjustment as a public attribute so that it
     # can be accessed from the description template.
     for item in items:
         item.description_thumbnail = item._adjusted[THUMBNAIL_SIZES[1]]
     return items
Esempio n. 8
0
    def render(self, context):
        video = self.video.resolve(context)

        # Backwards-compat: livesearch should just use the thumbnail_url.
        if getattr(video, '_livesearch', False):
            info_dict = AdjustmentInfoDict({
                'width': self.width,
                'height': self.height,
                'url': video.thumbnail_url
            })
        else:
            storage_path = None

            if video.has_thumbnail:
                storage_path = video.thumbnail_path
            elif video.feed_id and video.feed.has_thumbnail:
                storage_path = video.feed.thumbnail_path
            elif video.search_id and video.search.has_thumbnail:
                storage_path = video.search.thumbnail_path

            helper = AdjustmentHelper([storage_path],
                                      [Fill(width=self.width,
                                            height=self.height)])
            info_dict = helper.info_dicts()[0][1]

            # localtv_thumbnail has always fallen back in the code.
            if not info_dict:
                info_dict = AdjustmentInfoDict({
                    'width': self.width,
                    'height': self.height,
                    'url': staticfiles_storage.url('localtv/images/default_vid.gif')
                })
        
        if self.asvar is not None:
            context[self.asvar] = info_dict
            return ''
        return info_dict
Esempio n. 9
0
 def test_calculate__width(self):
     fill = Fill(width=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 10
0
 def test_calculate__strings(self):
     fill = Fill(height='100', max_width='50')
     self.assertEqual(fill.calculate((100, 100)), (50, 100))
Esempio n. 11
0
 def test_calculate__height(self):
     fill = Fill(height=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 12
0
 def test_calculate__max_width(self):
     fill = Fill(height=50, max_width=200)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 13
0
 def test_calculate__max_width__smaller(self):
     fill = Fill(height=100, max_width=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 100))
Esempio n. 14
0
 def test_calculate__width(self):
     fill = Fill(width=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 15
0
 def test_calculate__height(self):
     fill = Fill(height=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 16
0
 def test_calculate__unequal(self):
     fill = Fill(width=50, height=40)
     self.assertEqual(fill.calculate((100, 100)), (50, 40))
Esempio n. 17
0
 def test_calculate__unequal(self):
     fill = Fill(width=50, height=40)
     self.assertEqual(fill.calculate((100, 100)), (50, 40))
Esempio n. 18
0
 def test_calculate__max_width(self):
     fill = Fill(height=50, max_width=200)
     self.assertEqual(fill.calculate((100, 100)), (50, 50))
Esempio n. 19
0
 def test_calculate__max_width__smaller(self):
     fill = Fill(height=100, max_width=50)
     self.assertEqual(fill.calculate((100, 100)), (50, 100))
Esempio n. 20
0
 def test_calculate__strings(self):
     fill = Fill(height='100', max_width='50')
     self.assertEqual(fill.calculate((100, 100)), (50, 100))