如何在ImageMagick中同时使用流式和转换命令?

huangapple go评论59阅读模式
英文:

How do we use stream and convert commands together in imagemagick

问题

我了解从Imagemagick文档中,我们使用stream命令来处理大型图像。

Imagemagick Stream Interface

我有一个问题:我们如何将stream命令与convert命令结合使用?我们可以将stream命令的输出传输给convert命令吗?还是仅使用stream就足以实现所需的转换(例如裁剪和调整大小)?

是否可以提供任何示例命令?或者可以提供一些相关材料吗?比如针对裁剪和调整大小的用例?

谢谢。

英文:

I do understand from the imagemagick documentation that we do use stream command for processing large images.

Imagemagick Stream Interface

The question i have is: how do we use the stream command in conjunction with the convert command. Can we pipe the output of stream command to convert command or stream alone should be sufficient to achieve the needed transformations (eg: crop and resize)

Can someone provide any sample command ?? or maybe some material where i can find this ? let us say for a crop and resize use case ?

Thanks.

答案1

得分: 1

我对从一张12000x10000的图像的右下角提取一个100x100区域,然后将其调整大小为50x50并保存的各种方法进行了一些时间测试。

制作200MB的JPEG图像:

magick -size 12000x10000 xc: +noise random a.jpg

使用普通的ImageMagick进行裁剪和调整大小:

time magick a.jpg -crop 100x100+8000+8000 -resize 50 result.jpg
real	0m 2.38s
user	0m 2.10s
sys	0m 0.27s

使用stream进行裁剪和调整大小:

time magick stream -storage-type char -map rgb -extract 100x100+8000+8000 a.jpg - | magick -depth 8 -size 100x100 rgb:- -resize 50 result.jpg
real	0m 2.04s
user	0m 1.98s
sys	0m 0.05s

使用vips进行裁剪和调整大小:

time vips extract_area a.jpg .ppm 8000 8000 100 100 | vipsthumbnail --size 50x50 -o result.jpg stdin
real	0m 1.61s
user	0m 1.52s
sys	0m 0.08s

我的结论是,在这种情况下,使用stream的好处很小,而且vips略快一些。


TIFF格式允许将图像保存为可以由图像处理器查找的条带,而不需要读取所有中间内容。这在提取不靠近图像开头的块时非常有用。因此,我制作了一个具有rows-per-strip=500的TIFF图像:

magick -size 12000x10000 xc: +noise random -depth 8 -define tiff:rows-per-strip=500 a.tif

然后我重复了上述的3个测试:

使用普通的ImageMagick进行裁剪和调整大小:

time magick a.tif -crop 100x100+8000+8000 -resize 50 result.jpg
real	0m 0.83s
user	0m 0.44s
sys	0m 0.38s

使用stream进行裁剪和调整大小:

time magick stream -storage-type char -map rgb -extract 100x100+8000+8000 a.tif - | magick -depth 8 -size 100x100 rgb:- -resize 50 result.jpg
real	0m 0.82s
user	0m 0.44s
sys	0m 0.38s

使用vips进行裁剪和调整大小:

time vips extract_area a.tif .ppm 8000 8000 100 100 | vipsthumbnail --size 50x50 -o result.jpg stdin
real	0m 0.17s
user	0m 0.05s
sys	0m 0.12s

我的结论是,如果你想要做这种事情,使用TIFF格式和vips确实有明显的好处。

英文:

I did some timings of various ways to extract a 100x100 area from the bottom-right corner of a 12000x10000 image then resize it to 50x50 and save.

Make 200MB JPEG

magick -size 12000x10000 xc: +noise random a.jpg

Crop and resize with straight ImageMagick:

time magick a.jpg -crop 100x100+8000+8000 -resize 50 result.jpg
real	0m 2.38s
user	0m 2.10s
sys	    0m 0.27s

Crop and resize with stream:

time magick stream -storage-type char -map rgb -extract 100x100+8000+8000 a.jpg - | magick -depth 8 -size 100x100 rgb:- -resize 50 result.jpg
real	0m 2.04s
user	0m 1.98s
sys	    0m 0.05s

Crop and resize with vips:

time  vips extract_area a.jpg .ppm 8000 8000  100 100 | vipsthumbnail --size 50x50 -o result.jpg stdin 
real	0m 1.61s
user	0m 1.52s
sys	    0m 0.08s

My conclusion is that there is little benefit to using stream in this case, and that vips is somewhat faster.


The TIFF format allows images to be saved in strips that an image processor can seek to, without reading all the intermediate stuff. This is helpful when extracting chunks not near the start of images. So I made a TIFF with rows-per-strip=500

magick -size 12000x10000 xc: +noise random -depth 8 -define tiff:rows-per-strip=500 a.tif

Then I repeated the 3 tests from above:

Crop and resize with straight ImageMagick:

time magick a.tif -crop 100x100+8000+8000 -resize 50 result.jpg
real	0m 0.83s
user	0m 0.44s
sys	    0m 0.38s

Crop and resize with stream:

time magick stream -storage-type char -map rgb -extract 100x100+8000+8000 a.tif - | magick -depth 8 -size 100x100 rgb:- -resize 50 result.jpg
real	0m 0.82s
user	0m 0.44s
sys	    0m 0.38s

Crop and resize with vips:

time  vips extract_area a.tif .ppm 8000 8000  100 100 | vipsthumbnail --size 50x50 -o result.jpg stdin 
real	0m 0.17s
user	0m 0.05s
sys	    0m 0.12s

My conclusion is that there is a definite benefit to using TIFF format and vips if you are trying to do this sort of thing.

huangapple
  • 本文由 发表于 2023年7月13日 12:10:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76675861.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定