Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply --bigsurify to macOS icons only #7

Merged
merged 2 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions appicongen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,16 @@ def main():

# Resolve templates and (distinct) icon sizes

templates = {template for template in ICON_SIZES.keys() if args.all or arg_dict[template.replace('-', '_')]}
size_files = {size.filename: (size.scaled_width, size.scaled_height) for template in templates for size in ICON_SIZES[template]}
templates = {
template
for template in ICON_SIZES.keys()
if args.all or arg_dict[template.replace('-', '_')]
}
size_files = {
size.filename(suffix='b' if args.bigsurify and size.bigsurifiable else ''): size
for template in templates
for size in ICON_SIZES[template]
}

if not templates:
print('==> No templates specified, thus not generating any icons (use --all to generate all)')
Expand All @@ -61,15 +69,15 @@ def main():
print('==> Generating scaled icons...')
with open_image(input_path) as input_img:
bg_color = find_mean_color(input_img)
for filename, (scaled_width, scaled_height) in size_files.items():
for filename, size in size_files.items():
generate_icon(
input_img=input_img,
output_path=output_path / filename,
width=scaled_width,
height=scaled_height,
width=size.scaled_width,
height=size.scaled_height,
resize_mode=args.resize_mode,
bg_color=bg_color,
bigsurify=args.bigsurify
bigsurify=args.bigsurify and size.bigsurifiable,
)

# Generate manifest
Expand All @@ -79,12 +87,12 @@ def main():
'images': [{k: v for k, v in {
'size': size.size_str,
'expected-size': str(size.scaled_size),
'filename': size.filename,
'filename': filename,
'idiom': size.idiom,
'scale': size.scale_str,
'role': size.role,
'subtype': size.subtype,
}.items() if v} for template in templates for size in ICON_SIZES[template]]
}.items() if v} for filename, size in size_files.items()]
}
with open(output_path / args.manifest_name, 'w') as f:
f.write(json.dumps(manifest, indent=2))
Expand Down
11 changes: 7 additions & 4 deletions appicongen/size.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def scaled_width(self) -> int:
def scaled_height(self) -> int:
return int(self.height * self.scale)

@property
def filename(self) -> str:
return f'{self.scaled_width}x{self.scaled_height}.png'

@property
def width(self) -> Union[int, Fraction]:
return self.size * self.aspect_ratio
Expand All @@ -47,6 +43,13 @@ def size_str(self) -> str:
def scale_str(self) -> str:
return f'{self.scale}x'

@property
def bigsurifiable(self) -> bool:
return self.idiom == 'mac'

def filename(self, suffix: str='') -> str:
return f'{self.scaled_width}x{self.scaled_height}{suffix}.png'

def __str__(self) -> str:
return f'{self.size_str} ({self.scale}x)'

Expand Down