douzhao9608 2018-07-02 14:55
浏览 203

为什么imagemagick中的PNG图像要用readimage和writeimage花费很多时间?

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.

  • 写回答

1条回答 默认 最新

  • dongpaozhi5734 2018-07-03 06:50
    关注

    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:

    enter image description here

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

    enter image description here

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

    enter image description here


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

    enter image description here

    And when compressing an iPhone photo to a PNG:

    enter image description here


    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog