Корректировка ресайзинга методом crop
This commit is contained in:
10
resize.py
10
resize.py
@ -1,4 +1,5 @@
|
||||
#!/usr/bin/env python
|
||||
from __future__ import division
|
||||
import os, sys
|
||||
from PIL import Image
|
||||
from PIL import ImageEnhance
|
||||
@ -19,14 +20,15 @@ try:
|
||||
im = im.convert()
|
||||
if args.crop:
|
||||
width_crop = im.size[0]
|
||||
height_crop = im.size[0]*(args.width/args.height)
|
||||
height_crop = int(im.size[0]/(args.width/args.height))
|
||||
width_padding = 0
|
||||
height_padding = (im.size[1]-height_crop)/2
|
||||
height_padding = int((im.size[1]-height_crop)/2)
|
||||
if height_crop > im.size[1]:
|
||||
width_crop = im.size[1]*(args.height/args.width)
|
||||
width_crop = int(im.size[1]/(args.height/args.width))
|
||||
height_crop = im.size[1]
|
||||
width_padding = (im.size[0]-width_crop)/2
|
||||
width_padding = int((im.size[0]-width_crop)/2)
|
||||
height_padding = 0
|
||||
print((width_padding, height_padding, width_crop+width_padding, height_crop+height_padding))
|
||||
im_crop = im.crop((width_padding, height_padding, width_crop+width_padding, height_crop+height_padding))
|
||||
im_result = im_crop.resize(size, Image.ANTIALIAS)
|
||||
else:
|
||||
|
Reference in New Issue
Block a user