Collect images from the presentation and gather other information.
(self)
| 63 | return self.image_stats |
| 64 | |
| 65 | def collect_images(self): |
| 66 | """ |
| 67 | Collect images from the presentation and gather other information. |
| 68 | """ |
| 69 | for slide_index, slide in enumerate(self.presentation.slides): |
| 70 | for shape in slide.shape_filter(Picture): |
| 71 | image_path = pbasename(shape.data[0]) |
| 72 | self.image_stats[image_path] = { |
| 73 | "appear_times": 0, |
| 74 | "slide_numbers": set(), |
| 75 | "relative_area": shape.area / self.slide_area * 100, |
| 76 | "size": PIL.Image.open( |
| 77 | pjoin(self.config.IMAGE_DIR, image_path) |
| 78 | ).size, |
| 79 | } |
| 80 | self.image_stats[image_path]["appear_times"] += 1 |
| 81 | self.image_stats[image_path]["slide_numbers"].add(slide_index + 1) |
| 82 | for image_path, stats in self.image_stats.items(): |
| 83 | stats["slide_numbers"] = sorted(list(stats["slide_numbers"])) |
| 84 | ranges = self._find_ranges(stats["slide_numbers"]) |
| 85 | top_ranges = sorted(ranges, key=lambda x: x[1] - x[0], reverse=True)[:3] |
| 86 | top_ranges_str = ", ".join( |
| 87 | [f"{r[0]}-{r[1]}" if r[0] != r[1] else f"{r[0]}" for r in top_ranges] |
| 88 | ) |
| 89 | stats["top_ranges_str"] = top_ranges_str |
| 90 | |
| 91 | def _find_ranges(self, numbers): |
| 92 | """ |
no test coverage detected