mattyamonaca commited on
Commit
d8b8452
1 Parent(s): ca47a69
Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -37,12 +37,36 @@ def zip_png_files(folder_path):
37
  # zipファイルに追加
38
  zipf.write(file_path, arcname=os.path.relpath(file_path, folder_path))
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
  class webui:
42
  def __init__(self):
43
  self.demo = gr.Blocks()
44
 
45
  def undercoat(self, input_image, pos_prompt, neg_prompt, alpha_th, thickness, reference_flg, reference_img):
 
46
  org_line_image = input_image
47
  image = pil2cv(input_image)
48
  image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)
 
37
  # zipファイルに追加
38
  zipf.write(file_path, arcname=os.path.relpath(file_path, folder_path))
39
 
40
+ def resize_image(img, max_size=1024):
41
+ # 画像を開く
42
+ width, height = img.size
43
+ print(f"元の画像サイズ: 幅 {width} x 高さ {height}")
44
+
45
+ # 縦または横がmax_sizeを超えているかチェック
46
+ if width > max_size or height > max_size:
47
+ # 縦横比を保ちながらリサイズ
48
+ if width > height:
49
+ new_width = max_size
50
+ new_height = int(max_size * height / width)
51
+ else:
52
+ new_height = max_size
53
+ new_width = int(max_size * width / height)
54
+
55
+ # リサイズ実行
56
+ resized_img = img.resize((new_width, new_height), Image.ANTIALIAS)
57
+ print(f"リサイズ後の画像サイズ: 幅 {new_width} x 高さ {new_height}")
58
+ return resized_img
59
+ else:
60
+ return img
61
+
62
+
63
 
64
  class webui:
65
  def __init__(self):
66
  self.demo = gr.Blocks()
67
 
68
  def undercoat(self, input_image, pos_prompt, neg_prompt, alpha_th, thickness, reference_flg, reference_img):
69
+ input_image = resize_image(input_image)
70
  org_line_image = input_image
71
  image = pil2cv(input_image)
72
  image = cv2.cvtColor(image, cv2.COLOR_BGRA2RGBA)