File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919 runs-on : ubuntu-latest
2020 steps :
2121 - uses : actions/checkout@v6
22+ - uses : ./.github/actions/lfs-cached-checkout
2223 - uses : tox-dev/action-pre-commit-uv@v1
2324
2425 reuse :
Original file line number Diff line number Diff line change @@ -39,6 +39,15 @@ repos:
3939 scenes/quests/story_quests/(?!stella/)
4040 )
4141
42+ - repo : local
43+ hooks :
44+ - id : check-image-size
45+ name : check image dimensions
46+ entry : python tools/check-image-size.py
47+ language : python
48+ additional_dependencies : [Pillow]
49+ types_or : [png, jpeg, webp]
50+
4251 - repo : https://github.com/Scony/godot-gdscript-toolkit
4352 rev : 4.5.0
4453 hooks :
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ # /// script
3+ # dependencies = [
4+ # "pillow>=12.2.0",
5+ # ]
6+ # ///
7+
8+ # SPDX-FileCopyrightText: The Threadbare Authors
9+ # SPDX-License-Identifier: MPL-2.0
10+ """
11+ Fail if any given image file exceeds 4096px wide or 4096px high.
12+ """
13+
14+ import argparse
15+ import sys
16+
17+ from PIL import Image , UnidentifiedImageError
18+
19+ # https://docs.godotengine.org/en/stable/tutorials/3d/3d_rendering_limitations.html
20+ # “if you want your texture to display correctly on all platforms, you should
21+ # avoid using textures larger than 4096×4096”
22+ MAX_SIZE = 4096
23+
24+
25+ def check (path ) -> bool :
26+ try :
27+ with Image .open (path ) as im :
28+ width , height = im .size
29+ except (UnidentifiedImageError , OSError ) as e :
30+ print (f"{ path } : could not read image ({ e } )" , file = sys .stderr )
31+ return False
32+
33+ if width > MAX_SIZE or height > MAX_SIZE :
34+ print (
35+ f"{ path } : { width } x{ height } exceeds { MAX_SIZE } x{ MAX_SIZE } " ,
36+ file = sys .stderr ,
37+ )
38+ return False
39+
40+ return True
41+
42+
43+ def main () -> int :
44+ parser = argparse .ArgumentParser (description = __doc__ )
45+ parser .add_argument ("files" , nargs = "*" )
46+ args = parser .parse_args ()
47+
48+ return not all ([check (path ) for path in args .files ])
49+
50+
51+ if __name__ == "__main__" :
52+ sys .exit (main ())
You can’t perform that action at this time.
0 commit comments