Skip to content

Commit 2684add

Browse files
[Style] In make_namecard_kit, save large images as JPG
Affected subdirs are idol/produce, support, base, base/commu Also, forcefully convert image to RGB if JPG format is specified Side effects: - One must be mindful to avoid exporting images with "useful" alpha channels as JPG - In make_namecard_kit, the instruction-based coding style forces the user to give a resize argument before specifying 'jpg' format
1 parent 12e7479 commit 2684add

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

gkmasToolkit/blob.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,11 @@ def _export_img(
293293
img_resize = self._determine_new_size(img.size, ratio=img_resize)
294294
img = img.resize(img_resize, Image.LANCZOS)
295295

296-
img.save(path.with_suffix(f".{img_format.lower()}"), quality=100)
296+
try:
297+
img.save(path.with_suffix(f".{img_format.lower()}"), quality=100)
298+
except OSError: # cannot write mode RGBA as {img_format}
299+
img = img.convert("RGB")
300+
img.save(path.with_suffix(f".{img_format.lower()}"), quality=100)
297301
logger.success(f"{self._idname} extracted as {img_format.upper()}")
298302

299303
def _determine_new_size(

make_namecard_kit.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
from gkmasToolkit.utils import Logger
77

88

9-
# general
10-
# - bg_common…
11-
# - frame?
12-
# - misc…
139
instructions_dl = [
1410
(r"img_general_icon_contest-rank.*", "profile"),
1511
(r"img_general_meishi_illust_idol.*", "idol/full"),
1612
(r"img_general_meishi_illust_sd.*", "idol/mini", "2:3"),
17-
(r"img_general_cidol.*full\..*", "idol/produce", "9:16"),
18-
(r"img_general_cidol.*thumb-landscape-large.*", "idol/produce", "16:9"),
13+
(r"img_general_cidol.*full\..*", "idol/produce", "9:16", "jpg"),
14+
(r"img_general_cidol.*thumb-landscape-large.*", "idol/produce", "16:9", "jpg"),
1915
(r"img_general_cidol.*thumb-portrait.*", "idol/produce", "3:4"),
2016
(r"img_general_meishi_illust_sign.*", "idol/sign"),
21-
(r"img_general_csprt.*full\..*", "support", "16:9"),
22-
(r"img_general_meishi_base_story-bg.*", "base/commu", "16:9"),
23-
(r"img_general_meishi_base_(?!story-bg).*full\..*", "base", "16:9"),
17+
(r"img_general_csprt.*full\..*", "support", "16:9", "jpg"),
18+
(r"img_general_meishi_base_story-bg.*", "base/commu", "16:9", "jpg"),
19+
(r"img_general_meishi_base_(?!story-bg).*full\..*", "base", "16:9", "jpg"),
2420
(r"img_general_achievement_produce.*", "achievement/produce"),
2521
(r"img_general_achievement_common.*", "achievement/misc"),
2622
(r"img_general_meishi_illust_music-logo.*", "parts/logo", "3:2"),
@@ -60,11 +56,18 @@
6056

6157
for pattern, subdir, *config in instructions_dl:
6258
logger.info(f"Populating '{subdir}'")
59+
6360
ratio = config[0] if config else None
61+
fmt = config[1] if len(config) > 1 else "png"
62+
# In this case, all JPGs must be resized, but this remains unfixed
63+
# since this instruction-based coding style can hardly be generalized
64+
6465
manifest.download(
6566
pattern,
6667
path=target + subdir,
6768
categorize=False,
69+
extract_img=True,
70+
img_format=fmt,
6871
img_resize=ratio,
6972
)
7073

0 commit comments

Comments
 (0)