Batch convert Images on Windows and Linux

I encountered a common problem when preparing images for the web (e.g. this blog), from screenshots or from renders. These are usually available as .tiff or .pnm formats or have been processed with GIMP resulting in .xcf file. Converting these to .pngs or jpegs with GIMP or some viewer software makes it a click intensive task. There are a plenty of applications with GUIs for this task. These are however bloated with functions one normally does not need. There is a faster way to do this with a simple batch script.
One can for example use the convert tool from the ImageMagick package. There are binary releases for all operating systems including portable versions. The usage of the convert tool quite straight forward:

If you however want to process multiple images from a folder, you need to use script, that takes all the files, removes the extensions (e.g. .jpg) and replaces them with new ones (e.g. .png). A script for the Windows shell could look like this:

The tricky part is here understanding the Windows batch parameter modifiers. The %%~nf expands %%f (the f variable) to a file name without extension.

In case of Linux bash the script would look like this:

In this case it is good to know about the shell parameter expansion. In case of the suffix ${filename##*.} the longest matching pattern *. is removed from the beginning of the filename and in the case of the base file name ${filename%.*} the shortest matching trailing pattern .* is removed. Also the routine linux tool basename is used which strips the file name (and extension) of its path (if any).

One special case that should be taken into account are .xcf files from GIMP. In these fiels by default multiple layers can be used. Convert luckily provides a option to access these layers, using the [i] option (for accessing the i-th layer).

The Windows script for .xcf would then look like this:

And the Linux script for .xcf would look like this:

57 thoughts on “Batch convert Images on Windows and Linux”

  1. “Krojamsoft BatchRename” Tool is a powerful tool, that allows you to quickly rename all the files in a specified directory. You can remove spaces, replace spaces with underscore, uppercase/lowercase filename, add a prefix/suffix, remove/replace strings and also catalog files by adding an incremental number to the file name.

  2. Продам :
    транспортерные ленты
    транспортер ленточный
    где купить транспортерную ленту
    куплю транспортерную ленту
    расчет конвейера

    Звоните, о цене договоримся.

    Константин Маринич,

    тел: (067) 50-44-185

    ООО «МегаСТО»
    09113, Украина, г. Белая Церковь, ул. Турчанинова, 23
    Телефон: (044) 383-14-05, (04563) 4-69-89


  3. Choose payment method: Bank wire, WesternUnion, MoneyGram, Google Wallet, Webmoney.
    72TB File Storage 0day 1990-2017.
    IP restrictions: 3 IP addresses per user at the same time.
    Overal server’s speed: 500 Mbps.
    Easy to use: Most of genres are sorted by days.
    Server’s capacity: 72 TB for all FTP.
    More Seven years Of Archives.
    No Waiting Time, No captcha,No Speed Limit, No Ads.
    Never Deleted Original Albums, Labels, Save Time And Money.
    Updated On Daily: 20GB-50GB, 300-500 Albums 0-day WEB, Promo, CD, CDA, CDM, CDR, CDS, EP, LP, Vinyl…
    Up Time: 99%
    All Genre: House, Club, Techno, Trance, Dance, Italo-Dance, Eurodance, Drum and Bass, Psychedelic, Goa, PsyTrance, Progressive House, Electro, Euro-House, Club-House, Hardtechno, Tech-House, Dutch House, Minimal, Deep-House, Nu-Disco, Hardstyle, Hardcore, Jumpstyle, Electronic, Alternative, Alternative Rock, Ambient, Avantgarde, Ballad, Bass, Beat, Black Metal,Blues, Classical, Chanson, Country, Dance Hall, Death Metal, Disco, Ethnic, Folk, Folk-Rock, Funk, Gangsta Rap, Gothic Rock,Hard Rock, Heavy Metal, Hip-Hop, Indie, Industrial, Instrumental, Jazz, Jungle, Pop, Rock, Metal, Latin, Lo-Fi, New Age, Noise, Oldies, Pop-Folk, Progressive Rock, Psychedelic Rock, Punk Rock, Rap, Reggae, R&B, Rock & Roll, Soul, Soundtrack, Speech, Synthpop, Thrash Metal, Top 40, Vocal etc.
    Account delivery time: 1 to 48 hours.

  4. Hi! My name is Annie Haslow. I’m SEO in Indian pharm company “PanjabPharm”.
    We produce many items of quality drugs but due to Big Pharma patents we are unable to supply you with it.
    Our engeneers have more than 20 years expirience in complex med researches. So my only way to let you know about us is to send this message.
    Welcome to our site!

Leave a Reply

Your email address will not be published. Required fields are marked *