如何使用ImageMagick"转换"将输出文件名打印到控制台工具?

时间:2015-10-14 22:25:50

标签: imagemagick output filenames imagemagick-convert

当我使用ImageMagick转换图像"转换"工具我想获取创建文件的文件名。

使用" -monitor"命令行参数我只能得到输入文件名。

3 个答案:

答案 0 :(得分:2)

更新了答案

最简单,最直接的方法是使用-verbose选项,如下所示:

convert rose: rose: rose: -verbose image_%04d.png
rose:=>image_0000.png[0] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000
rose:=>image_0001.png[1] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000
rose:=>image_0002.png[2] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000

我花了好几次迭代,并且为了达到目的而花了太多时间,但是我会在下面留下我以前的想法,以防有人想要尝试一些"离墙#34 ; 并且,让我们说,"设计" ,做类似事情的方法......

选项1

您可以使用%p转义序列以及-format+identify,如下所示:

convert rose: rose: rose: -format "image_%p.png\n" -identify image_%04d.png
image_0.png
image_1.png
image_2.png

是的,我知道它并不完美,但它可能足以让你开始。

选项2

这可能是另一种选择:

convert rose: rose: rose: -verbose +identify 'rose-%04d.png' | grep png
rose:=>rose-0000.png[0] PPM 70x46 70x46+0+0 8-bit sRGB 7.06KB 0.000u 0:00.000
rose:=>rose-0001.png[1] PPM 70x46 70x46+0+0 8-bit sRGB 7.06KB 0.000u 0:00.000
rose:=>rose-0002.png[2] PPM 70x46 70x46+0+0 8-bit sRGB 7.06KB 0.000u 0:00.000

选项3

convert -debug "Trace" rose: rose: rose: image_%04d.png 2>&1 | grep "\.png" | sort -u
image_%04d.png
image_0000.png
image_0001.png
image_0002.png

选项4

另一种选择可能是创建一个文件来标记当前时间,然后运行命令并查找比您在开始之前创建的文件更新的文件:

touch b4; sleep 1; convert rose: rose: rose: image_%04d.png

find . -newer b4

./image_0000.png
./image_0001.png
./image_0002.png

选项5

使用%o(输出文件名)转义的另一个选项 - 建议 - 以及-verbose

convert rose: rose: rose: -format "%o" -verbose -identify image_%04d.png
rose:=>image_0000.png[0] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000
rose:=>image_0001.png[1] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000
rose:=>image_0002.png[2] PPM 70x46 70x46+0+0 8-bit sRGB 6.97KB 0.000u 0:00.000

答案 1 :(得分:0)

这更像是一种解决方法......如果使用变量提前指定输出,则可以从变量中获取输出。以下是使用shell脚本的示例:

#!/bin/bash                                                                     
export fn="fuzzy-magick"
export inp="$fn.png"
export outp="$fn.gif"
convert $inp $outp
echo "Output was "$outp

答案 2 :(得分:0)

我在Mark Setchel answer上进行了扩展,以获取文件名:

FILES=( $(
  convert <arguments> \
    -format "%o\n" -verbose -identify \
    <output> \
    2>&1 > /dev/null | sed -nEe 's/.*=>(.*)\[.*/\1/p'
) )

例如:

$ FILES=( $(
  convert rose: \
    \( -clone 0 -modulate 100,100,33.3 \) \
    \( -clone 0 -modulate 100,100,66.6 \) \
    -format "%o\n" -verbose -identify \
    rose.png \
    2>&1 > /dev/null | sed -nEe 's/.*=>(.*)\[.*/\1/p'
) )
$ echo ${FILES[0]}
rose-0.png
$ echo ${FILES[1]}
rose-1.png
$ echo ${FILES[2]}
rose-2.png
$ echo ${#FILES[@]}
3