|
@@ -36,7 +36,7 @@ class index_path(Load):
|
|
|
def post(self, *args, **kwargs):
|
|
|
url = self.request.protocol + "://" + self.request.host
|
|
|
file_metas = self.request.files["file"]
|
|
|
- type = self.input('type', 1)
|
|
|
+ crop = self.input('crop', 1)
|
|
|
# print(file_metas)
|
|
|
day = str(date.today())
|
|
|
day = day.split('-')
|
|
@@ -48,23 +48,25 @@ class index_path(Load):
|
|
|
with open(file_path, 'wb') as up:
|
|
|
up.write(meta['body'])
|
|
|
|
|
|
- if type:
|
|
|
+ if crop:
|
|
|
#裁图类型,暂时居中裁图
|
|
|
- file_path = self.crop(file_path)
|
|
|
+ file_path = cropImage(file_path)
|
|
|
self.out('yes', {'src':url + file_path.replace(Demeter.path + 'runtime', '')})
|
|
|
|
|
|
- def crop(file):
|
|
|
- img = Image.open(file) #打开图片句柄
|
|
|
- width = img.size[0]
|
|
|
- height = img.size[1]
|
|
|
- size = 0
|
|
|
- if width < height:
|
|
|
- size = width
|
|
|
- else:
|
|
|
- size = height
|
|
|
- #img.thumbnail((500, 500))
|
|
|
- left = width/4
|
|
|
- crop = img.crop((left, 0, size+left, size))
|
|
|
- file = file + '_crop_center.jpg'
|
|
|
- crop.save(file)
|
|
|
- return file
|
|
|
+def cropImage(file):
|
|
|
+ img = Image.open(file)
|
|
|
+ width = img.size[0]
|
|
|
+ height = img.size[1]
|
|
|
+ size = 0
|
|
|
+ if width == height:
|
|
|
+ return file
|
|
|
+ elif width < height:
|
|
|
+ size = width
|
|
|
+ else:
|
|
|
+ size = height
|
|
|
+ #img.thumbnail((500, 500))
|
|
|
+ left = width/4
|
|
|
+ crop = img.crop((left, 0, size+left, size))
|
|
|
+ file = file + '_crop_center.jpg'
|
|
|
+ crop.save(file)
|
|
|
+ return file
|