为什么readimage和writeimage在imagemagick中花费了大量时间来处理PNG图像? [英] Why does readimage and writeimage takes a lot of time for PNG images in imagemagick?

查看:854
本文介绍了为什么readimage和writeimage在imagemagick中花费了大量时间来处理PNG图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Imagemagick版本7.0.5-4执行图像处理操作,例如裁剪,调整大小等,使用



查看质量设置(0-100)如何影响时间和JPEG输出的大小:





现在看看如果使用相同的质量设置会发生什么(0-100 )生成PNG输出时:





将iPhone照片压缩为PNG时:








希望您可以看到使用配置文件中的一个质量设置来处理PNG和JPEG以及照片和卡通/线条图并不理想。


I'm using Imagemagick version 7.0.5-4 to perform image processing operations like crop, resize etc with go-graphics library. I also manage a pool of magickwand objects.

Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib

The read time of image to MagickWand object as magickWand.ReadImage(<url>) in png images is very high compared that of jpg images. For images of size around 22kb, reading a jpg file takes around 300ms and that of png image takes around 1-2 minutes.

Edited:

When a single request is sent to server, the read operation takes around 20ms, but when on load of 100rps, it goes till 2-4 minutes. This trend is only in png images, not in jpg.

Any ideas on what can be done different in reading png files and how it can be made performant? Its fine to reduce the quality of images to around 60%. Tried options like SetImageDepth but it made no difference.

解决方案

The compression quality parameter has a different effect and meaning when dealing with PNG files from when dealing with JPEG files.

PNG compression is always lossless and the appearance is never affected by the quality. As I cannot see your images, I would suggest you either don't bother compressing since it will happen anyway, or that you use a quality of 75. If you tell me you are saving cartoons or line drawings, I might advise differently.

Please have a read here and do some experiments yourself with the tradeoff between time and filesize.

I have made you some plots to show the effect on time to compress and compressed size for different quality settings using two different kinds of images - cartoons and photos - so you can see the effect.

Here is a cartoon:

Look at how the quality setting (0-100) affects time and size with JPEG output:

Now look what happens if you use those same quality settings (0-100) when generating PNG output:


Now let's look at compressing an iPhone photo to JPEG:

And when compressing an iPhone photo to a PNG:


Hopefully you can see that using one quality setting from your config file for both PNG and JPEG and with photos and cartoons/line drawings is not ideal.

这篇关于为什么readimage和writeimage在imagemagick中花费了大量时间来处理PNG图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆