Add "optimize alternative icons" insight handling#417
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #417 +/- ##
==========================================
+ Coverage 79.77% 79.96% +0.18%
==========================================
Files 147 149 +2
Lines 11850 12027 +177
Branches 1208 1223 +15
==========================================
+ Hits 9453 9617 +164
- Misses 1962 1969 +7
- Partials 435 441 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| size (1024px) before optimization, since they only need quality for homescreen display. | ||
| """ | ||
|
|
||
| # Icon size constants matching Swift implementation |
| resized, file_info.path, file_info.file_type, resized_size, file_info.size | ||
| ) | ||
| except Exception as exc: | ||
| logger.error("Failed to process %s: %s", file_info.path, exc) |
There was a problem hiding this comment.
Use logger.exception, it will automatically capture the exception details. Also avoid using string interpolation in the message so it doesn't create separate issues for us each time.
| if res := self._check_heic_minification(img, resized_size): | ||
| minify_savings, minified_size = res.savings, res.optimized_size | ||
| except Exception as exc: | ||
| logger.error("Failed to analyze resized icon: %s", exc) |
| _MAX_WORKERS = 4 | ||
|
|
||
| @abstractmethod | ||
| def _iter_files_to_analyze(self, input: InsightsInput) -> Iterable[FileInfo]: |
There was a problem hiding this comment.
Can these two methods be combined into something like _find_images() -> List[FileInfo]? The de-duping can be merged into that as well. The current structure here is a bit awkward IMO, the iterator just converts it to a list anyways. It looks like the subclasses are responsible for returning a list of images that should be considered for processing.
There was a problem hiding this comment.
Similarly, the _analyze_image_optimization override doesn't fit in nicely here since we lose the ThreadPoolExecutor logic and duplicate a lot of size-checking code. Maybe there could be some kind of overridable "preprocess" or "transform" method that gets called before _analyze_image_optimization so that method doesn't have to be overriden?
fe416bb to
c9a7754
Compare
c9a7754 to
5870161
Compare
4bf0194 to
9236935
Compare
Closes EME-50
I tried to match the emerge implementation as much as possible. There's a ~6% size difference between the ultimately optimized icons compared to what's produced by the emerge code But it is consistent across all the images and appears to be related to the fact that we are using a different HEIC encoder:
I tried reducing the image quality from 85% to 75% to get the size reduction closer to emerge's but it didn't reduce the size enough to justify an extra 10% loss in quality