MCPcopy Create free account
hub / github.com/openai/plugins / main

Function main

plugins/game-studio/scripts/normalize_sprite_strip.py:120–148  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

118
119
120def main() -> None:
121 args = parse_args()
122 if args.frames < 1:
123 raise SystemExit("--frames must be at least 1.")
124 if args.frame_size < 1:
125 raise SystemExit("--frame-size must be positive.")
126 if args.lock_frame1 and not args.anchor:
127 raise SystemExit("--lock-frame1 requires --anchor.")
128
129 strip = Image.open(args.input).convert("RGBA")
130 slots = split_strip(strip, args.frames)
131 contents = [crop_to_content(slot, args.alpha_threshold) for slot in slots]
132 anchor_image, anchor_content = load_anchor(args.anchor, args.alpha_threshold)
133 max_width, max_height = max_content_size([*contents, anchor_content])
134 scale = min(args.frame_size / max_width, args.frame_size / max_height)
135
136 out_dir = Path(args.out_dir)
137 out_dir.mkdir(parents=True, exist_ok=True)
138
139 for index, content in enumerate(contents, start=1):
140 if index == 1 and args.lock_frame1:
141 assert anchor_image is not None
142 if anchor_image.width == args.frame_size and anchor_image.height == args.frame_size:
143 frame = anchor_image
144 else:
145 frame = compose_frame(anchor_content, args.frame_size, scale)
146 else:
147 frame = compose_frame(content, args.frame_size, scale)
148 frame.save(out_dir / f"{index:02d}.png")
149
150
151if __name__ == "__main__":

Callers 1

Calls 6

split_stripFunction · 0.85
crop_to_contentFunction · 0.85
load_anchorFunction · 0.85
max_content_sizeFunction · 0.85
compose_frameFunction · 0.85
parse_argsFunction · 0.70

Tested by

no test coverage detected