(width: int, height: int, *, video_mode: bool = False)
| 121 | |
| 122 | |
| 123 | def _aspect_from_dimensions(width: int, height: int, *, video_mode: bool = False) -> Optional[str]: |
| 124 | if width <= 0 or height <= 0: |
| 125 | return None |
| 126 | |
| 127 | ratio = width / height |
| 128 | inferred = min( |
| 129 | ASPECT_RATIO_FLOAT_MAP.items(), |
| 130 | key=lambda item: abs(ratio - item[1]), |
| 131 | )[0] |
| 132 | |
| 133 | if video_mode and inferred not in {"landscape", "portrait"}: |
| 134 | return "portrait" if height > width else "landscape" |
| 135 | return inferred |
| 136 | |
| 137 | |
| 138 | def _infer_aspect_ratio_from_images( |
no outgoing calls
no test coverage detected