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

Function padding_image

wan/utils/utils.py:352–378  ·  view source on GitHub ↗
(images, new_width, new_height)

Source from the content-addressed store, hash-verified

350 return ref_image
351
352def padding_image(images, new_width, new_height):
353 new_image = Image.new('RGB', (new_width, new_height), (255, 255, 255))
354
355 aspect_ratio = images.width / images.height
356 if new_width / new_height > 1:
357 if aspect_ratio > new_width / new_height:
358 new_img_width = new_width
359 new_img_height = int(new_img_width / aspect_ratio)
360 else:
361 new_img_height = new_height
362 new_img_width = int(new_img_height * aspect_ratio)
363 else:
364 if aspect_ratio > new_width / new_height:
365 new_img_width = new_width
366 new_img_height = int(new_img_width / aspect_ratio)
367 else:
368 new_img_height = new_height
369 new_img_width = int(new_img_height * aspect_ratio)
370
371 resized_img = images.resize((new_img_width, new_img_height))
372
373 paste_x = (new_width - new_img_width) // 2
374 paste_y = (new_height - new_img_height) // 2
375
376 new_image.paste(resized_img, (paste_x, paste_y))
377
378 return new_image
379
380def timer(func):
381 def wrapper(*args, **kwargs):

Callers 1

get_image_latentFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected