我正在使用以下代码,该代码负责使用python的枕头库更改图像分辨率。我在aws lambda上部署代码。代码运行正常,但在调整大小时有一个简单的逻辑缺陷。该代码旨在如下工作: 1.将图像上载到S3存储桶 2.代码将图像大小调整为2个不同的维度,并将其上传到不同的存储桶中。
但代码上传了相同维度的2张图片,我无法理解为什么
from __future__ import print_function
import boto3
import os
import sys
import uuid
from PIL import Image
import PIL.Image
s3_client = boto3.client('s3')
def resize_image_DOG(image_path, resized_path):
with Image.open(image_path) as image:
dim=(3840,2160)
image.resize(dim)
image.save(resized_path)
def resize_image_CAT(image_path, resized_path):
with Image.open(image_path) as image:
dim=(1920,1080)
image.resize(dim)
image.save(resized_path)
def handler(event, context):
for record in event['Records']:
bucket = record['s3']['bucket']['name']
key = record['s3']['object']['key']
download_path = '/tmp/{}{}'.format(uuid.uuid4(), key)
upload_path_1 = '/tmp/resized-{}{}'.format('test1',key)
upload_path_2 = '/tmp/resized-{}{}'.format('test2',key)
s3_client.download_file(bucket, key, download_path)
resize_image_DOG(download_path, upload_path_1)
resize_image_CAT(download_path, upload_path_2)
s3_client.upload_file(upload_path_1, '{}resized'.format(bucket), key+'xxxhdpi-3840*2160'+'.png')
s3_client.upload_file(upload_path_2, '{}resized'.format(bucket), key+'xxxhdpi-1920*1080'+'.png')
上传到调整大小的桶的2个已调整大小的图像具有相同的尺寸,即第一个resize_image_DOG维度(3340x2160)仅,但名称正确,请帮助
答案 0 :(得分:1)
我查看了枕头文档:<MenuItem x:Name="MyMenu"
IsEnabled="{Binding Items.Count, Converter={StaticResource HasItemsConverter}}"
Header="MENU">
</MenuItem>
返回已调整大小的图片,并且不会更改传递的图片。
因此,它应该是
image.resize()