简体   繁体   English

用魔杖转换为PNG的jpg图像变得更大

[英]jpg images converted to PNG with wand get much larger

I've got a batch process that converts uploaded images using wand to generate thumbnails and resized versions. 我有一个批处理过程,使用魔杖转换上传的图像,以生成缩略图和调整大小的版本。 The problem is that the converted images get a lot larger than the original image. 问题是转换后的图像比原始图像大得多。 An uploaded jpg (1024x768) that was 239kB ends up over 1.2MB at 800x600. 上传的jpg(1024x768)为239kB,最终超过1.2MB,800x600。 If I just resize but don't change format, the image is 132kB. 如果我只是调整大小但不更改格式,则图像为132kB。 Here's the relevent bit of code from my script. 这是我脚本中相关的代码。

im1 = Image(blob=file) sizemedium = '800x600' im1.transform(resize=sizemedium) im1.format ='png' medfile = im1.make_blob()

Keep the format. 保持格式。 PNG uses a different way of "encoding" color and is not very optimized for photos (it is better for illustrations, icons and clip art). PNG使用不同的“编码”颜色方式,并不是非常适合照片(它更适合插图,图标和剪贴画)。

You'll see it works fine if there is a limited number of colors in the image. 如果图像中的颜色数量有限,您会发现它可以正常工作。

Rule-of-thumb for image formats is to use JPEG for photos, PNG for anything else. 图像格式的经验法则是将JPEG用于照片,将PNG用于其他任何事物。

The thing is that PNGs can be larger than JPGs, specially when you are storing photos, so that might be the problem. 问题是PNG可能比JPG更大,特别是当你存储照片时,这可能是问题所在。 If you do not need a PNG for a specific reason I would just keep the JPG format. 如果您因特定原因不需要PNG,我会保留JPG格式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM