Skip to content

Commit

Permalink
Merge pull request #7 from fwcd/bigsurify-macos-only
Browse files Browse the repository at this point in the history
Apply `--bigsurify` to macOS icons only
  • Loading branch information
fwcd authored Sep 28, 2023
2 parents a6f466c + ffed652 commit dfc790b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
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

0 comments on commit dfc790b

Please sign in to comment.