ImageMagick convert jpg images to gif slow

匿名 (未验证) 提交于 2019-12-03 02:33:02

问题:

I am using Magick++(IM 7.0.3 platform:CentOS Linux release 7.0) to convert images to gif. I create Image objects from files, the problem is that when I convert 9 png files(each 50kb) to gif, it taks only 50ms. but when it turns to 9 jpg files (each 20kb), it takes 1900ms. What is the reason behind? How can I make it faster with jpg files?

 for(int i = 2; i < argc-1; i++)   {     // I pass the file path from command line     cout << argv[i] << endl;     Image img(argv[i]);     img.animationDelay(delay);     img.magick("GIF");     frames.push_back(img);   }   long mergestart = getCurrentTime();   Magick::Blob tmpBlob;   Magick::writeImages(frames.begin(), frames.end(), &tmpBlob); 

回答1:

I would guess that the PNG files are either palettised or contain relatively few colours, whereas the JPEGs will have thousands of colours, so ImageMagick will be forced to do a lot more work to reduce and optimise the colours for the relatively small palette of 256 colours a GIF can contain.

Check my theory on your files by running:

identify -verbose Any.PNG 

and

identify -verbose Any.JPG 

and look at the Number of colours.

Alternatively, you can use this command to count the colours:

identify -format %k AnyImage.png 

If you want to make it faster because you have thousands of files to process, you could use multi-threading, or something like GNU Parallel to get more done at once.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!