不使用内存调整巨大的jpeg大小 [英] Resize huge jpeg using no memory
问题描述
我需要在不使用RAM的情况下调整巨大(最大30000x30000)的JPEG文件的大小,速度没有关系,有什么办法吗?我尝试了不同的库(nativejpg和其他库),但是它们使用了所有可用的RAM,并且由于诸如内存不足或没有足够的存储空间来处理此命令之类的错误而崩溃。我什至尝试了命令行实用程序imagemagick,但它也使用了千兆字节的内存。
I need to resize huge (up to 30000x30000) JPEG files using no RAM, speed doesn't matter, is there any way to do so? I tried different libraries (nativejpg and others) but they use all free RAM and and crash with errors like "Out of memory" or "Not enough storage is available to process this command". I even tried command line utility imagemagick, but it also uses gigabytes of memory.
推荐答案
我建议您看看 vips
。 此处中记录了该文件。
I would suggest you have a look at vips
. It is documented here.
我可以使用ImageMagick创建10000x10000的噪声图像
I can create a 10000x10000 image of noise like this with ImageMagick
convert -size 10000x10000! xc:gray50 +noise poisson image.jpg
并检查其是否正确,例如:
and check it is the correct size like this:
identify image.jpg
image.jpg JPEG 10000x10000 10000x10000+0+0 8-bit sRGB 154.9MB 0.000u
我现在可以使用 vip
调整10000x10000图像的大小降至2500x2500这样
I can now use vips
to resize the 10000x10000 image down to 2500x2500 like this
time vipsthumbnail image.jpg -s 2500 -o small.jpg --vips-leak
memory: high-water mark 20.48 MB
real 0m1.974s
user 0m2.158s
sys 0m0.096s
请注意,内存使用量仅达到20MB的峰值
检查结果使用ImageMagick
Check the result like this with ImageMagick
identify result.jpg
result.jpg JPEG 2500x2500 2500x2500+0+0 8-bit sRGB 1.33MB 0.000u 0:00.000
也请参阅技术说明,有关性能和内存使用- 此处。
Have a look at the Technical Note too, regarding performance and memory usage - here.
您也可以从 C
以及命令行。
You can also call it from C
as well as the command line.
这篇关于不使用内存调整巨大的jpeg大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!