From ec11827b6305b17481ab2325b5a488a1bbed009f Mon Sep 17 00:00:00 2001 From: Rod S Date: Thu, 17 Jun 2021 10:17:07 -0700 Subject: [PATCH] Utility to confirm sizing --- size_check.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 size_check.py diff --git a/size_check.py b/size_check.py new file mode 100644 index 000000000..db3c338b8 --- /dev/null +++ b/size_check.py @@ -0,0 +1,42 @@ +"""Sanity check image sizes and svg viewboxes.""" +from PIL import Image +from pathlib import Path +from lxml import etree + + +def _check_image(base_dir, image_dir): + assert image_dir.is_dir() + expected_size = (int(image_dir.name), int(image_dir.name)) + + for image_file in image_dir.iterdir(): + with Image.open(image_file) as image: + actual_size = image.size + if expected_size != actual_size: + print(f"bad_dim {image_file.relative_to(base_dir)} actual {actual_size} expected {expected_size}") + +def _check_svg(base_dir, svg_dir): + expected_viewbox = (0.0, 0.0, 128.0, 128.0) + for svg_file in svg_dir.iterdir(): + if not svg_file.name.startswith("emoji_u"): + continue + assert svg_file.is_file() + with open(svg_file) as f: + actual_viewbox = etree.parse(f).getroot().attrib["viewBox"] + actual_viewbox = tuple(float(s) for s in actual_viewbox.split(" ")) + if expected_viewbox != actual_viewbox: + print(f"bad_dim {svg_file.relative_to(base_dir)} actual {actual_viewbox} expected {expected_viewbox}") + +def main(): + base_dir = Path(__file__).parent + image_dir = base_dir / "png" + svg_dir = base_dir / "svg" + + assert image_dir.is_dir() + assert svg_dir.is_dir() + + for size_dir in image_dir.iterdir(): + _check_image(base_dir, size_dir) + _check_svg(base_dir, svg_dir) + +if __name__ == "__main__": + main() \ No newline at end of file