我想使用PIL库缩放和裁剪图像。例如:我有3位用户的图片:
我应该只将图像保持在500x500px的分辨率,因此我想对这些图像进行中心裁剪并将其设置为500x500px。我该怎么办?
我尝试了堆栈溢出的一些解决方案:
# This works fine but it just crops a 500x500px square from the image
img.crop((width//2 - 500//2, height//2 - 500//2, width//2 + 500//2, height//2 + 500//2))
# Maybe i did something wrong but nearly everything is black (pic 1)
img.thumbnail([500, 500])
img.crop((width//2 - 500//2, height//2 - 500//2, width//2 + 500//2, height//2 + 500//2))