ImageMagick无序转换

问题描述 投票:1回答:1

我有100个图像名为img0.jpg到img99.jpg转换为pdf文件。问题是

convert img*.jpg out.pdf

以1,11,2,22等的顺序添加页面。如何在imagemagick中定义顺序?

imagemagick imagemagick-convert
1个回答
1
投票

使用零填充数字对您的页面进行编号,以便ImageMagick按顺序对其进行编号:

img000.jpg
img001.jpg
img002.jpg
...
img098.jpg

然后你的原始命令应该工作。


或者,让bash按顺序枚举文件并将名称输入ImageMagick,如下所示:

magick img{0..99}.jpg result.pdf

要么:

for file in img{0..99}.jpg; do echo $file; done | magick @- result.pdf

或者按照上面的第一个示例重命名文件,但使用Perl rename

rename --dry-run 's/\D//g; $_=sprintf("f-%05d.jpg",$_)' f*jpg

样本输出

'f0.jpg' would be renamed to 'f-00000.jpg'
'f1.jpg' would be renamed to 'f-00001.jpg'
'f10.jpg' would be renamed to 'f-00010.jpg'
'f11.jpg' would be renamed to 'f-00011.jpg'
'f12.jpg' would be renamed to 'f-00012.jpg'

您可以使用ls -v,在这种情况下您可以尝试:

magick $(ls -v img*jpg) result.pdf
© www.soinside.com 2019 - 2024. All rights reserved.