From cbaeffde6880bca62349af09cd243bb4e45f11fd Mon Sep 17 00:00:00 2001 From: j Date: Thu, 24 Aug 2023 23:39:54 +0200 Subject: [PATCH] Image.ANTIALIAS->Image.LANCZOS --- pandora/archive/extract.py | 4 ++-- pandora/document/fulltext.py | 2 +- pandora/item/timelines.py | 6 +++--- requirements.txt | 1 + scripts/item_icon.pandora.py | 6 +++--- scripts/list_icon.pandora.py | 4 ++-- scripts/poster.0xdb.py | 12 ++++++------ scripts/poster.indiancinema.py | 6 +++--- scripts/poster.padma.py | 2 +- scripts/poster.pandora.py | 8 ++++---- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/pandora/archive/extract.py b/pandora/archive/extract.py index cf3598c7e..696e2e91b 100644 --- a/pandora/archive/extract.py +++ b/pandora/archive/extract.py @@ -459,7 +459,7 @@ def resize_image(image_source, image_output, width=None, size=None): height = max(height, 1) if width < source_width: - resize_method = Image.ANTIALIAS + resize_method = Image.LANCZOS else: resize_method = Image.BICUBIC output = source.resize((width, height), resize_method) @@ -605,7 +605,7 @@ def timeline_strip(item, cuts, info, prefix): print(frame, 'cut', c, 'frame', s, frame, 'width', widths[s], box) # FIXME: why does this have to be frame+1? frame_image = Image.open(item.frame((frame+1)/fps)) - frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.ANTIALIAS) + frame_image = frame_image.crop(box).resize((widths[s], timeline_height), Image.LANCZOS) for x_ in range(widths[s]): line_image.append(frame_image.crop((x_, 0, x_ + 1, timeline_height))) frame += widths[s] diff --git a/pandora/document/fulltext.py b/pandora/document/fulltext.py index 7e246b97d..c4c9aaff4 100644 --- a/pandora/document/fulltext.py +++ b/pandora/document/fulltext.py @@ -161,7 +161,7 @@ class FulltextMixin: img = Image.alpha_composite(img, overlay) img = img.convert("RGB") aspect = img.size[0] / img.size[1] - resize_method = Image.ANTIALIAS + resize_method = Image.LANCZOS if img.size[0] >= img.size[1]: width = size height = int(size / aspect) diff --git a/pandora/item/timelines.py b/pandora/item/timelines.py index f6ff9f72e..7e2e12f8b 100644 --- a/pandora/item/timelines.py +++ b/pandora/item/timelines.py @@ -71,7 +71,7 @@ def join_tiles(source_paths, durations, target_path): if not w or large_tile_i < large_tile_n - 1: w = 60 data['target_images']['large'] = data['target_images']['large'].resize( - (w, small_tile_h), Image.ANTIALIAS + (w, small_tile_h), Image.LANCZOS ) if data['target_images']['small']: data['target_images']['small'].paste( @@ -90,7 +90,7 @@ def join_tiles(source_paths, durations, target_path): if data['full_tile_widths'][0]: resized = data['target_images']['large'].resize(( data['full_tile_widths'][0], large_tile_h - ), Image.ANTIALIAS) + ), Image.LANCZOS) data['target_images']['full'].paste(resized, (data['full_tile_offset'], 0)) data['full_tile_offset'] += data['full_tile_widths'][0] data['full_tile_widths'] = data['full_tile_widths'][1:] @@ -196,7 +196,7 @@ def join_tiles(source_paths, durations, target_path): #print(image_file) image_file = '%stimeline%s%dp.jpg' % (target_path, full_tile_mode, small_tile_h) data['target_images']['full'].resize( - (full_tile_w, small_tile_h), Image.ANTIALIAS + (full_tile_w, small_tile_h), Image.LANCZOS ).save(image_file) #print(image_file) diff --git a/requirements.txt b/requirements.txt index dbec6568f..ddc241e54 100644 --- a/requirements.txt +++ b/requirements.txt @@ -20,3 +20,4 @@ elasticsearch<8 future pytz pypdfium2 +Pillow>=10 diff --git a/scripts/item_icon.pandora.py b/scripts/item_icon.pandora.py index 4f4b1e354..c069bbbb2 100755 --- a/scripts/item_icon.pandora.py +++ b/scripts/item_icon.pandora.py @@ -20,11 +20,11 @@ def render_icon(frame, timeline, icon): frame_image = Image.open(frame) if frame else Image.new('RGB', (1024, 768), (0, 0, 0)) frame_image_ratio = frame_image.size[0] / frame_image.size[1] if frame_ratio < frame_image_ratio: - frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.ANTIALIAS) + frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.LANCZOS) left = int((frame_image.size[0] - frame_width) / 2) frame_image = frame_image.crop((left, 0, left + frame_width, frame_height)) else: - frame_image = frame_image.resize((frame_width, int(frame_width / frame_image_ratio)), Image.ANTIALIAS) + frame_image = frame_image.resize((frame_width, int(frame_width / frame_image_ratio)), Image.LANCZOS) top = int((frame_image.size[1] - frame_height) / 2) frame_image = frame_image.crop((0, top, frame_width, top + frame_height)) icon_image.paste(frame_image, (0, 0)) @@ -36,7 +36,7 @@ def render_icon(frame, timeline, icon): mask_image = Image.open(os.path.join(static_root, 'iconTimelineOuterMask.png')) icon_image.paste(timeline_image, (timeline_left - 4, timeline_top - 4), mask=mask_image) timeline_image = Image.open(timeline) if timeline else Image.new('RGB', (timeline_width, timeline_height), (0, 0, 0)) - timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.ANTIALIAS) + timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.LANCZOS) mask_image = Image.open(os.path.join(static_root, 'iconTimelineInnerMask.png')) icon_image.paste(timeline_image, (timeline_left, timeline_top), mask=mask_image) # we're using jpegs with border-radius diff --git a/scripts/list_icon.pandora.py b/scripts/list_icon.pandora.py index 8c930b7db..3d0fbbf1c 100755 --- a/scripts/list_icon.pandora.py +++ b/scripts/list_icon.pandora.py @@ -24,11 +24,11 @@ def render_list_icon(frames, icon): frame_image_ratio = frame_image.size[0] / frame_image.size[1] frame_width_ = frame_width + (1 if i % 2 == 1 else 0) if frame_ratio < frame_image_ratio: - frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.ANTIALIAS) + frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.LANCZOS) left = int((frame_image.size[0] - frame_width_) / 2) frame_image = frame_image.crop((left, 0, left + frame_width_, frame_height)) else: - frame_image = frame_image.resize((frame_width_, int(frame_width_ / frame_image_ratio)), Image.ANTIALIAS) + frame_image = frame_image.resize((frame_width_, int(frame_width_ / frame_image_ratio)), Image.LANCZOS) top = int((frame_image.size[1] - frame_height) / 2) frame_image = frame_image.crop((0, top, frame_width_, top + frame_height)) icon_image.paste(frame_image, (i % 2 * frame_width + (1 if i % 2 == 2 else 0), diff --git a/scripts/poster.0xdb.py b/scripts/poster.0xdb.py index 9b9f24701..7666702a4 100755 --- a/scripts/poster.0xdb.py +++ b/scripts/poster.0xdb.py @@ -64,11 +64,11 @@ def render_poster(data, poster): frame_image = Image.open(frame) frame_image_ratio = frame_image.size[0] / frame_image.size[1] if frame_ratio < frame_image_ratio: - frame_image = frame_image.resize((int(frame_size[1] * frame_image_ratio), frame_size[1]), Image.ANTIALIAS) + frame_image = frame_image.resize((int(frame_size[1] * frame_image_ratio), frame_size[1]), Image.LANCZOS) left = int((frame_image.size[0] - frame_size[0]) / 2) frame_image = frame_image.crop((left, 0, left + frame_size[0], frame_size[1])) else: - frame_image = frame_image.resize((frame_size[0], int(frame_size[0] / frame_image_ratio)), Image.ANTIALIAS) + frame_image = frame_image.resize((frame_size[0], int(frame_size[0] / frame_image_ratio)), Image.LANCZOS) top = int((frame_image.size[1] - frame_size[1]) / 2) frame_image = frame_image.crop((0, top, frame_size[0], top + frame_size[1])) poster_image.paste(frame_image, (0, 0)) @@ -77,7 +77,7 @@ def render_poster(data, poster): # logo logo_image = Image.open(os.path.join(static_root, 'logo.0xdb.png')) - logo_image = logo_image.resize(logo_size, Image.ANTIALIAS) + logo_image = logo_image.resize(logo_size, Image.LANCZOS) for y in range(logo_size[1]): for x in range(logo_size[0]): poster_color = poster_image.getpixel((margin + x, margin + y)) @@ -95,11 +95,11 @@ def render_poster(data, poster): if small_frame_image: small_frame_image_ratio = small_frame_image.size[0] / small_frame_image.size[1] if small_frame_ratio < small_frame_image_ratio: - small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.ANTIALIAS) + small_frame_image = small_frame_image.resize((int(small_frame_size[1] * small_frame_image_ratio), small_frame_size[1]), Image.LANCZOS) left = int((small_frame_image.size[0] - small_frame_size[0]) / 2) small_frame_image = small_frame_image.crop((left, 0, left + small_frame_size[0], small_frame_size[1])) else: - small_frame_image = small_frame_image.resize((small_frame_size[0], int(small_frame_size[0] / small_frame_image_ratio)), Image.ANTIALIAS) + small_frame_image = small_frame_image.resize((small_frame_size[0], int(small_frame_size[0] / small_frame_image_ratio)), Image.LANCZOS) top = int((small_frame_image.size[1] - small_frame_size[1]) / 2) small_frame_image = small_frame_image.crop((0, top, small_frame_size[0], top + small_frame_size[1])) poster_image.paste(small_frame_image, (i * small_frame_size[0], frame_size[1])) @@ -189,7 +189,7 @@ def render_poster(data, poster): # timeline if timeline: timeline_image = Image.open(timeline) - timeline_image = timeline_image.resize(timeline_size, Image.ANTIALIAS) + timeline_image = timeline_image.resize(timeline_size, Image.LANCZOS) poster_image.paste(timeline_image, (0, poster_size[1] - timeline_size[1])) else: draw.rectangle(((0, poster_size[1] - timeline_size[1]), poster_size), fill=image_color) diff --git a/scripts/poster.indiancinema.py b/scripts/poster.indiancinema.py index bc37fca5e..9146af319 100755 --- a/scripts/poster.indiancinema.py +++ b/scripts/poster.indiancinema.py @@ -160,7 +160,7 @@ def render_poster(data, poster): if frame_ratio < frame_image_ratio: frame_image = frame_image.resize( (int(frame_height * frame_image_ratio), frame_height), - Image.ANTIALIAS + Image.LANCZOS ) left = int((frame_image.size[0] - poster_width) / 2) frame_image = frame_image.crop( @@ -169,7 +169,7 @@ def render_poster(data, poster): else: frame_image = frame_image.resize( (poster_width, int(poster_width / frame_image_ratio)), - Image.ANTIALIAS + Image.LANCZOS ) top = int((frame_image.size[1] - frame_height) / 2) frame_image = frame_image.crop( @@ -187,7 +187,7 @@ def render_poster(data, poster): timeline_image = Image.open(timeline) timeline_image = timeline_image.resize( (poster_width, timeline_height), - Image.ANTIALIAS + Image.LANCZOS ) poster_image.paste(timeline_image, (0, poster_height - timeline_height)) else: diff --git a/scripts/poster.padma.py b/scripts/poster.padma.py index 015aaa9b8..bf949801f 100755 --- a/scripts/poster.padma.py +++ b/scripts/poster.padma.py @@ -33,7 +33,7 @@ def render_poster(data, poster): timeline_lines = 16 if timeline: timeline_image = Image.open(timeline) - timeline_image = timeline_image.resize((10240, timeline_height), Image.ANTIALIAS) + timeline_image = timeline_image.resize((10240, timeline_height), Image.LANCZOS) for i in range(timeline_lines): line_image = timeline_image.crop((i * poster_width, 0, (i + 1) * poster_width, 64)) poster_image.paste(line_image, (0, i * timeline_height)) diff --git a/scripts/poster.pandora.py b/scripts/poster.pandora.py index 5f1965623..eef8cdace 100755 --- a/scripts/poster.pandora.py +++ b/scripts/poster.pandora.py @@ -62,11 +62,11 @@ def render_poster(data, poster): frame_image = Image.open(frame) frame_image_ratio = frame_image.size[0] / frame_image.size[1] if frame_ratio < frame_image_ratio: - frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.ANTIALIAS) + frame_image = frame_image.resize((int(frame_height * frame_image_ratio), frame_height), Image.LANCZOS) left = int((frame_image.size[0] - frame_width) / 2) frame_image = frame_image.crop((left, 0, left + frame_width, frame_height)) else: - frame_image = frame_image.resize((frame_width, int(frame_width / frame_image_ratio)), Image.ANTIALIAS) + frame_image = frame_image.resize((frame_width, int(frame_width / frame_image_ratio)), Image.LANCZOS) top = int((frame_image.size[1] - frame_height) / 2) frame_image = frame_image.crop((0, top, frame_width, top + frame_height)) poster_image.paste(frame_image, (0, 0)) @@ -76,7 +76,7 @@ def render_poster(data, poster): timeline_height = 64 if timeline: timeline_image = Image.open(timeline) - timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.ANTIALIAS) + timeline_image = timeline_image.resize((timeline_width, timeline_height), Image.LANCZOS) poster_image.paste(timeline_image, (0, frame_height)) # text @@ -115,7 +115,7 @@ def render_poster(data, poster): logo_height = 32 logo_image = Image.open(os.path.join(static_root, '..', '..', 'static', 'png', 'logo.png')) logo_width = int(round(logo_height * logo_image.size[0] / logo_image.size[1])) - logo_image = logo_image.resize((logo_width, logo_height), Image.ANTIALIAS) + logo_image = logo_image.resize((logo_width, logo_height), Image.LANCZOS) logo_left = text_width - text_margin - logo_width logo_top = text_bottom - text_margin - logo_height for y in range(logo_height):