简体   繁体   English

使用Imagemagick压缩非常高分辨率的图像文件

[英]compress very large resolution image file using Imagemagick

I have some scanned images of resolution 20400x28056. 我有一些分辨率为20400x28056的扫描图像。 I want them to be compressed using imagemagick. 我希望使用imagemagick压缩它们。 I tried convert ToBeCompressed.jpeg -quality 70 output.jpeg but this command is making my laptop crashed. 我尝试convert ToBeCompressed.jpeg -quality 70 output.jpeg但是此命令使笔记本电脑崩溃了。 I think it is not able to handle such large resolution. 我认为它不能处理这么大的分辨率。 Any suggestions please. 有任何建议请。

A few things to check... your image corresponds to around 1.6GB of raw data so you may find you need to be running a 64-bit environment, rather than 32-bit. 需要检查的几件事...您的图像对应大约1.6GB的原始数据,因此您可能会发现需要运行64位环境而不是32位环境。 If you are on Windows, you may need to be running on an NTFS filesystem rather than FAT because FAT filesystems, though they can be up to 130GB in size, cannot support individual files larger than 2GB, or maybe 4GB if you are lucky. 如果您使用的是Windows,则可能需要在NTFS文件系统而不是FAT上运行,因为FAT文件系统的最大大小为130GB,不能支持大于2GB的单个文件,如果幸运的话,可能支持4GB。

Finally, could you consider resizing the image rather than reducing its quality, if you resize it on-the-fly as you read it in, you may do better since it is less resource-intensive. 最后,您是否可以考虑调整图像的大小而不是降低图像的质量,如果阅读过程中即时调整其大小,则可能会做得更好,因为它占用的资源较少。 So, say you decided you could accept an image half the length on each side (1/4 of the original area) 因此,假设您决定接受两边长度一半的图像(原始面积的1/4)

convert input.jpg[50%x50%] -quality 70 output.jpg

Depending on what you actually want to do with the image afterwards, you could use ImageMagick's stream utility to split the image into chunks. 根据之后实际要处理的图像,可以使用ImageMagick的stream实用程序将图像拆分为多个块。 It reads the image a row at a time so it only uses very little memory. 它一次读取图像一次,因此仅占用很少的内存。 So, to get the two halves of the image into a raw format, you could do 因此,要将图像的两半转换成原始格式,您可以

stream  -extract 20400x14028+0+0     ToBeCompressed.jpg tophalf.rgb
stream  -extract 20400x14028+0+14028 ToBeCompressed.jpg bottomhalf.rgb

Then, if you want to convert those raw RGB files to JPG, you can do 然后,如果要将这些原始RGB文件转换为JPG,可以执行

convert -depth 8 -size 20400x14028 tophalf.rgb tophalf.jpg

Another avenue you could pursue might be vips , which is described here . 你可以追求的另一种途径可能是vips ,这是描述在这里

So, if your image is called BigBoy.jpg you could do this to set the quality to 60, for example: 因此,如果您的图片名为BigBoy.jpg ,则可以将其质量设置为60,例如:

vips jpegsave BigBoy.jpg BB60.jpg --Q=60

which results in this on my system 这导致我的系统上

ls -l Bi* BB60.jpg
-rw-r--r--  1 mark  staff  270283175 19 Mar 14:17 BB60.jpg
-rw-r--r--  1 mark  staff  997198223 19 Mar 14:07 BigBoy.jpg

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

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