Thumbnails for images and videos #87

Merged
Anna Sirota merged 28 commits from thumbnails into main 2024-04-25 17:50:58 +02:00
2 changed files with 5 additions and 5 deletions
Showing only changes of commit b071559152 - Show all commits

View File

@ -126,14 +126,14 @@ class UtilsTest(TestCase):
def test_make_thumbnails(self, mock_resize_image): def test_make_thumbnails(self, mock_resize_image):
self.assertEqual( self.assertEqual(
{ {
'1080p': {'path': 'thumbnails/fo/foobar_1920x1080.png', 'size': (1920, 1080)}, '1080p': {'path': 'thumbnails/fo/foobar_1920x1080.png', 'size': [1920, 1080]},
'360p': {'path': 'thumbnails/fo/foobar_640x360.png', 'size': (640, 360)}, '360p': {'path': 'thumbnails/fo/foobar_640x360.png', 'size': [640, 360]},
}, },
make_thumbnails(TEST_FILES_DIR / 'test_preview_image_0001.png', 'foobar'), make_thumbnails(TEST_FILES_DIR / 'test_preview_image_0001.png', 'foobar'),
) )
self.assertEqual(len(mock_resize_image.mock_calls), 2) self.assertEqual(len(mock_resize_image.mock_calls), 2)
for expected_size in ((1920, 1080), (640, 360)): for expected_size in ([1920, 1080], [640, 360]):
with self.subTest(expected_size=expected_size): with self.subTest(expected_size=expected_size):
mock_resize_image.assert_any_call( mock_resize_image.assert_any_call(
ANY, ANY,

View File

@ -237,9 +237,9 @@ def make_thumbnails(
thumbnails = {} thumbnails = {}
abs_path = os.path.join(settings.MEDIA_ROOT, source_path) abs_path = os.path.join(settings.MEDIA_ROOT, source_path)
image = Image.open(abs_path) image = Image.open(abs_path)
for size_key, (w, h) in THUMBNAIL_SIZES.items(): for size_key, size in THUMBNAIL_SIZES.items():
w, h = size
output_path = get_thumbnail_upload_to(file_hash, width=w, height=h) output_path = get_thumbnail_upload_to(file_hash, width=w, height=h)
size = (w, h)
with tempfile.TemporaryFile() as f: with tempfile.TemporaryFile() as f:
logger.info('Resizing %s to %s (%s)', abs_path, size, output_format) logger.info('Resizing %s to %s (%s)', abs_path, size, output_format)
resize_image( resize_image(