How to use the first image sequence in a multiple cropping process in ImageMagick

吃可爱长大的小学妹 提交于 2021-01-28 12:20:24

问题


I want resize, crop and concatenate really many images. I don't want to write the intermediate results to disk, just the final result only.

My script is :

montage -mode concatenate \
\( test.jpg -thumbnail "150x100>" -background white -gravity center -extent 150x100 -page 150x100+0+0 \) \
\( -clone 0 -crop 23x16+80+0  -background white -extent 23x16 \)  \
\( -clone 0 -crop 23x16+16+87 -background white -extent 23x16 \) \
...
-delete 0 -quality 100% thumb.jpg

I got always the following error:

montage.im6: geometry does not contain image `test.jpg' @ warning/transform.c/CropImage/574.

I tried to use the "repage" and "page" parameters, but I was unsuccessful with them.

Any idea?

Update

Mark asked for examples. So I try to write down the different steps which I would like to merge in one single step:

convert logo: test.jpg

convert test.jpg -thumbnail "150x100>" -background white -gravity center -extent 150x100 -page 150x100+0+0 test.resized.jpg

montage -mode concatenate test.resized.jpg \
    \( -clone 0 -crop 23x16+80+20  -background white -extent 23x16 \) \
    \( -clone 0 -crop 23x16+92+74 -background white -extent 23x16 \) \
    \( -clone 0 -crop 23x16+100+80 -background white -extent 23x16 \) \
    -delete 0 -quality 100% result.thumb.jpg

And the results: you can see here the expected result.

http://phspring.nl/stackoverflow28101334.jpg


回答1:


I must admit this one has me mystified! I cannot get it to work how you tried, or how I would want to do it at all. I found that I can only make it work if I add a +repage but if I do that it forgets the -extent, so I keep ending up with 2 commands. I also find that +clone refuses to work in place of -clone 0 for this example, which also mystifies me.

The only way I can make it work, and avoid the intermediate file is to stream the output of the first convert to the second one.

convert logo: -resize "150x100>" -background white -gravity center -extent 150x100 JPG:- | \
    convert JPG:- \
       \( -clone 0 -crop 23x16+80+20  \) \
       \( -clone 0 -crop 23x16+92+74  \) \
       \( -clone 0 -crop 23x16+100+80 \) \
       -delete 0 +append out.jpg


来源:https://stackoverflow.com/questions/28101334/how-to-use-the-first-image-sequence-in-a-multiple-cropping-process-in-imagemagic

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