-
-
Notifications
You must be signed in to change notification settings - Fork 3
Image Optimization: Ensure AppIcon exclusion logic isn't too aggressive #418
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -71,6 +71,7 @@ def _resize_icon_for_analysis(self, img: Image.Image) -> Image.Image: | |
| ) | ||
|
|
||
| def _is_alternate_icon_file(self, file_info: FileInfo, alternate_icon_names: set[str]) -> bool: | ||
| return file_info.file_type.lower() in self.OPTIMIZABLE_FORMATS and any( | ||
| Path(file_info.path).stem.startswith(name) for name in alternate_icon_names | ||
| return ( | ||
| file_info.file_type.lower() in self.OPTIMIZABLE_FORMATS | ||
| and Path(file_info.path).stem in alternate_icon_names | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. dont include images just because "AppIcon" is a prefix in the image's name |
||
| ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| from PIL import Image, ImageFile | ||
|
|
||
| from launchpad.size.insights.insight import Insight, InsightsInput | ||
| from launchpad.size.models.apple import AppleAppInfo | ||
| from launchpad.size.models.common import FileInfo | ||
| from launchpad.size.models.insights import ( | ||
| ImageOptimizationInsightResult, | ||
|
|
@@ -184,18 +185,42 @@ class ImageOptimizationInsight(BaseImageOptimizationInsight): | |
| """Analyse image optimisation opportunities in iOS apps.""" | ||
|
|
||
| def _find_images(self, input: InsightsInput) -> List[FileInfo]: | ||
| app_info = input.app_info if isinstance(input.app_info, AppleAppInfo) else None | ||
| alternate_icon_names = ( | ||
| set(app_info.alternate_icon_names) if app_info and app_info.alternate_icon_names else set() | ||
| ) | ||
| primary_icon_name = app_info.primary_icon_name if app_info else None | ||
|
|
||
| images: List[FileInfo] = [] | ||
| for fi in input.file_analysis.files: | ||
| if fi.file_type == "car": | ||
| images.extend(c for c in fi.children if self._is_optimizable_image_file(c)) | ||
| elif self._is_optimizable_image_file(fi): | ||
| images.extend( | ||
| c | ||
| for c in fi.children | ||
| if self._is_optimizable_image_file( | ||
| c, alternate_icon_names, primary_icon_name, from_asset_catalog=True | ||
| ) | ||
| ) | ||
| elif self._is_optimizable_image_file(fi, alternate_icon_names, primary_icon_name, from_asset_catalog=False): | ||
| images.append(fi) | ||
| return images | ||
|
|
||
| def _is_optimizable_image_file(self, file_info: FileInfo) -> bool: | ||
| def _is_optimizable_image_file( | ||
| self, | ||
| file_info: FileInfo, | ||
| alternate_icon_names: set[str], | ||
| primary_icon_name: str | None, | ||
| from_asset_catalog: bool, | ||
| ) -> bool: | ||
| if file_info.file_type.lower() not in self.OPTIMIZABLE_FORMATS: | ||
| return False | ||
| name = Path(file_info.path).name | ||
| if name.startswith(("AppIcon", "iMessage App Icon")): | ||
|
|
||
| if any(part.endswith(".stickerpack") for part in file_info.path.split("/")): | ||
| return False | ||
| return not any(part.endswith(".stickerpack") for part in file_info.path.split("/")) | ||
|
|
||
| # We can't guarantee that iMessage app's will have their icons specified in the Info.plist, so be conservative here | ||
| if not from_asset_catalog: | ||
| return not Path(file_info.path).name.startswith(("AppIcon", "iMessage App Icon")) | ||
|
|
||
| stem = Path(file_info.path).stem | ||
| return stem != primary_icon_name and stem not in alternate_icon_names | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't include any images that should be considered for the "alternative icon" insight for the "image optimization" insight |
||
Uh oh!
There was an error while loading. Please reload this page.