1+ import io
12import logging
23from pathlib import Path
34
4- from zimscraperlib .inputs import compute_descriptions
5+ from zimscraperlib .image .conversion import convert_image , convert_svg2png
6+ from zimscraperlib .image .probing import format_for
7+ from zimscraperlib .image .transformation import resize_image
8+ from zimscraperlib .inputs import compute_descriptions , handle_user_provided_file
59from zimscraperlib .zim import Creator , metadata
610
711from fcc2zim .build import build_command
@@ -81,10 +85,36 @@ def __init__(self):
8185 else :
8286 logger .info (f"ZIM path: { self .zim_path } " )
8387
84- logo_path = Path (__file__ ).parent .joinpath ("assets" , "fcc_48.png" )
88+ if context .illustration :
89+ logo_path = handle_user_provided_file (context .illustration )
90+ if not logo_path :
91+ raise ValueError (f"Logo not found at { context .illustration } " )
92+ else :
93+ logo_path = Path (__file__ ).parent .joinpath ("assets" , "fcc_48.png" )
8594 if not logo_path .exists ():
8695 raise ValueError (f"Logo not found at { logo_path } " )
8796
97+ illustration = io .BytesIO ()
98+ illustration_format = format_for (logo_path , from_suffix = False )
99+ if illustration_format == "SVG" :
100+ convert_svg2png (
101+ logo_path ,
102+ illustration ,
103+ metadata .DefaultIllustrationMetadata .illustration_size ,
104+ metadata .DefaultIllustrationMetadata .illustration_size ,
105+ )
106+ else :
107+ if illustration_format != "PNG" :
108+ convert_image (logo_path , illustration , fmt = "PNG" )
109+ else :
110+ illustration = io .BytesIO (logo_path .read_bytes ())
111+ resize_image (
112+ illustration ,
113+ width = metadata .DefaultIllustrationMetadata .illustration_size ,
114+ height = metadata .DefaultIllustrationMetadata .illustration_size ,
115+ method = "cover" ,
116+ )
117+
88118 self .creator = Creator (self .zim_path , "index.html" ).config_metadata (
89119 std_metadata = metadata .StandardMetadataList (
90120 Name = metadata .NameMetadata (context .name ),
@@ -94,7 +124,7 @@ def __init__(self):
94124 Publisher = metadata .PublisherMetadata (context .publisher ),
95125 Date = metadata .DateMetadata (context .start_date ),
96126 Illustration_48x48_at_1 = metadata .DefaultIllustrationMetadata (
97- logo_path . read_bytes ()
127+ illustration
98128 ),
99129 Description = metadata .DescriptionMetadata (context .description ),
100130 LongDescription = (
0 commit comments