将一堆图像从svg转换为png

时间:2017-07-17 08:51:53

标签: svg imagemagick png imagemagick-convert

我需要将svg转换为png文件夹中的所有图像。让我们说图像被称为test1.svg,test2.svg,...,testn.svg。使用以下脚本:

for i in *.svg
do
    convert "$i" PNG24:"$i".png
done

正确完成工作,图像名为test1.svg.png,test2.svg.png,...,testn.svg.png。我的问题是:

1)是否可以将输出图像称为test1.png,test2.png,...,testn.png,基本上从名称中删除'svg'部分?

2)是否可以将它们直接发送到其他目录?

谢谢!

1 个答案:

答案 0 :(得分:4)

是。您可以创建另一个目录并将其发送到此处:

>>> Request.query = {'foo': 1, 'bar': 2, 'spam': 3, 'eggs': 4}
>>> loop.run_until_complete(func(Request))
{'foo': 1, 'bar': 2, 'spam': 3, 'eggs': 4, 'missing': '10'}
>>> Request.query = {'foo': 1, 'bar': 2, 'spam': 3, 'eggs': 4, 'missing': 15}
>>> loop.run_until_complete(func(Request))
{'foo': 1, 'bar': 2, 'spam': 3, 'eggs': 4, 'missing': 15}
>>> Request.query = {'foo': 1, 'bar': 2, 'spam': 3}
>>> loop.run_until_complete(func(Request))
---------------------------------------------------------------------------
KeyError: 'eggs'

如果你有很多图片需要做,并且你在macOS或Linux上,我会建议 GNU Parallel 来更快地完成工作:

mkdir other
for i in *.jpg; do
   convert "$i" PNG24:other/"${i%jpg}png"
done
相关问题