MCPcopy Create free account
hub / github.com/Francis-Rings/FlashPortrait / padding_image

Function padding_image

wan/data/utils.py:143–169  ·  view source on GitHub ↗
(images, new_width, new_height)

Source from the content-addressed store, hash-verified

141 return resized_frame
142
143def padding_image(images, new_width, new_height):
144 new_image = Image.new('RGB', (new_width, new_height), (255, 255, 255))
145
146 aspect_ratio = images.width / images.height
147 if new_width / new_height > 1:
148 if aspect_ratio > new_width / new_height:
149 new_img_width = new_width
150 new_img_height = int(new_img_width / aspect_ratio)
151 else:
152 new_img_height = new_height
153 new_img_width = int(new_img_height * aspect_ratio)
154 else:
155 if aspect_ratio > new_width / new_height:
156 new_img_width = new_width
157 new_img_height = int(new_img_width / aspect_ratio)
158 else:
159 new_img_height = new_height
160 new_img_width = int(new_img_height * aspect_ratio)
161
162 resized_img = images.resize((new_img_width, new_img_height))
163
164 paste_x = (new_width - new_img_width) // 2
165 paste_y = (new_height - new_img_height) // 2
166
167 new_image.paste(resized_img, (paste_x, paste_y))
168
169 return new_image
170
171def resize_image_with_target_area(img: Image.Image, target_area: int = 1024 * 1024) -> Image.Image:
172 """

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected