如何用枕头将图像调整为多尺寸

时间:2019-08-22 09:15:24

标签: python-3.x image-processing python-imaging-library image-resizing

我有一个拍摄图像的服务,然后将其调整为多种尺寸。

使用的库:

  • 烧瓶
  • 枕头

我使用threading库,但出现此错误:SyntaxError: broken PNG file (chunk b'G:\x88(') 我的代码:

def upload(file):
create_if_not_exists(UPLOAD_FOLDER)
org_file_path = os.path.join(UPLOAD_FOLDER, secure_filename(file.filename))
file.save(org_file_path)
parallel_resizer(Image.open(org_file_path), file.filename)

def parallel_resizer(img, filename):
for size in ImageSize:
    threading.Thread(target=resize, args=(img, size, img.size, filename,)).start()


def resize(img, target_size, size, filename):
print("######", filename, target_size.name)
width = size[0]
height = size[1]
filePath = os.path.join(UPLOAD_FOLDER, target_size.name, secure_filename(filename))
newWidth = int(width * target_size.value)
newHeight = int(height * target_size.value)
resized = img.resize((newWidth, newHeight), Image.ANTIALIAS)
resized.save(filePath)

如何并行调整大小和图像至多个大小? 对于这种情况还有其他解决方案吗?

0 个答案:

没有答案