ImageMagick: convert to keep same name for converted image

前端 未结 4 1351
暖寄归人
暖寄归人 2020-12-24 13:03

I am converting .psd to .png files inside folder with one. How to keep same name of every file in folder with different extension ?

For example I enter in folder ima

相关标签:
4条回答
  • If you are on Linux, Unix or Mac OSX, you could use in a terminal window with Bash shell:

    for i in *.psd; do
         convert $i ${i/.psd/.png}
    done
    

    I deliberately do not advertise mogrify any more. It is too dangerous for every user who doesn't know it already, and who comes to this website to ask for help. mogrify is overwriting your original files in some cases (of course not when converting PSD->PNG)

    0 讨论(0)
  • 2020-12-24 13:54

    I like the top answer,

    that being said, in later versions of ImageMagick, the command is

    convert *.psd -set filename:basename "%[basename]" "%[filename:basename].png"
    

    as also mentioned by @jan-glx and @jomel imperio

    0 讨论(0)
  • 2020-12-24 13:57

    Or, even simpler:

    mogrify -format png *.psd
    
    0 讨论(0)
  • 2020-12-24 13:59

    Use the -set and formatting options.

    convert *.psd -set filename:base "%[basename]" "%[filename:base].png"
    

    See "Long Form Attribute Percent Escapes" and "Filename Percent Escapes" docs.

    Update

    The mogrify utility that ships with imagemagick can also be used.

    mogrify -format png *.psd
    

    Note: Be careful with mogrify as the docs state...

    This tool is similiar to convert except that the original image file is overwritten (unless you change the file suffix with the -format option) with any changes you request.

    0 讨论(0)
提交回复
热议问题