acmyu commited on
Commit
979c652
·
1 Parent(s): 7aba721

fix image padding

Browse files
Files changed (1) hide show
  1. main.py +5 -1
main.py CHANGED
@@ -173,6 +173,7 @@ def load_models():
173
  #load_models()
174
 
175
  def img_pad(img, tw, th, transparent=False):
 
176
  img.thumbnail((tw, th))
177
  if transparent:
178
  new_img = Image.new('RGBA', (tw, th), (0, 0, 0, 0))
@@ -180,12 +181,15 @@ def img_pad(img, tw, th, transparent=False):
180
  new_img = Image.new("RGB", (tw, th), (0, 0, 0))
181
  left = (tw - img.width) // 2
182
  top = (th - img.height) // 2
 
183
  new_img.paste(img, (left, top))
184
  return new_img
185
 
186
 
187
  def resize_pad(img, tw, th, transparent):
188
  w, h = img.size
 
 
189
 
190
  if tw/th > w/h:
191
  tw = int(th * w/h)
@@ -194,7 +198,7 @@ def resize_pad(img, tw, th, transparent):
194
 
195
  img = img.resize((tw, th), Image.BICUBIC)
196
 
197
- return img_pad(img, tw, th, transparent)
198
 
199
 
200
  def resize_and_pad(img, target_img):
 
173
  #load_models()
174
 
175
  def img_pad(img, tw, th, transparent=False):
176
+ #print('pad', tw, th)
177
  img.thumbnail((tw, th))
178
  if transparent:
179
  new_img = Image.new('RGBA', (tw, th), (0, 0, 0, 0))
 
181
  new_img = Image.new("RGB", (tw, th), (0, 0, 0))
182
  left = (tw - img.width) // 2
183
  top = (th - img.height) // 2
184
+ #print(left, top)
185
  new_img.paste(img, (left, top))
186
  return new_img
187
 
188
 
189
  def resize_pad(img, tw, th, transparent):
190
  w, h = img.size
191
+ orig_tw = tw
192
+ orig_th = th
193
 
194
  if tw/th > w/h:
195
  tw = int(th * w/h)
 
198
 
199
  img = img.resize((tw, th), Image.BICUBIC)
200
 
201
+ return img_pad(img, orig_tw, orig_th, True)
202
 
203
 
204
  def resize_and_pad(img, target_img):