图像调整大小导致垂直条(python和PIL)

时间:2022-11-08 00:25:43

This in being used in django view.

这在django视图中使用。

Im trying to reduce the size of a incoming image to create an thumbnail. To simplify things, I made the resize width/height the same as the original image (i've tried making it smaller and the exact same problem occurred.

我试图减少传入图像的大小来创建缩略图。为简化起见,我将调整大小的宽度/高度设置为与原始图像相同(我尝试将其缩小并发生完全相同的问题。

    basewidth = 350
    baseheight = 467
    img = Image.open(aobj.useravatar)
    img.convert('RGB')  # suggestion found in * 
    img.resize((basewidth, baseheight), PIL.Image.ANTIALIAS)
    img.save(file, format='JPEG', quality=100)

When downloaded, the file looks like this: Vertical Lines

下载时,文件如下所示:垂直线条

The original file (take from the server) looks like this: Original

原始文件(从服务器获取)如下所示:原始文件

2 个解决方案

#1


0  

Can you try this?

你能试试吗?

basewidth = 350
baseheight = 467
img = Image.open(aobj.useravatar)
img = img.thumbnail((basewidth, baseheight), Image.ANTIALIAS)
img.save(file, format='JPEG', quality=100)

#2


0  

If I save the files as a "PNG" the resultant image is perfect, so the code s/b:

如果我将文件保存为“PNG”,结果图像是完美的,所以代码s / b:

basewidth = 350
baseheight = 467
img = Image.open(aobj.useravatar)
img.thumbnail((basewidth, baseheight), Image.ANTIALIAS)
img.save(file, format='PNG', quality=100)

Yayyy.

#1


0  

Can you try this?

你能试试吗?

basewidth = 350
baseheight = 467
img = Image.open(aobj.useravatar)
img = img.thumbnail((basewidth, baseheight), Image.ANTIALIAS)
img.save(file, format='JPEG', quality=100)

#2


0  

If I save the files as a "PNG" the resultant image is perfect, so the code s/b:

如果我将文件保存为“PNG”,结果图像是完美的,所以代码s / b:

basewidth = 350
baseheight = 467
img = Image.open(aobj.useravatar)
img.thumbnail((basewidth, baseheight), Image.ANTIALIAS)
img.save(file, format='PNG', quality=100)

Yayyy.