batch png to jpg drop in conversion

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Dread Knight
Posts: 3
Joined: 2015-04-25T20:34:09-07:00
Authentication code: 6789
Contact:

batch png to jpg drop in conversion

Post by Dread Knight »

Hello!

I'm want to save up some hdd space and decided to batch convert my image collection into jpg files as quite a few of the images there are in png format.

Did some tests with the command line but I can't quite manage to replace the png images with jpg versions while also deleting the original png and having the new jpg use the same file name. Gave both convert and mogrify a go, any ideas?

Code: Select all

convert ephemeral:*.png *.jpg
This code above almost does the job with the exception of not maintaining the original file names :?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch png to jpg drop in conversion

Post by snibgo »

Windows BAT syntax:

Code: Select all

convert *.png -set filename:myname %%t %%[filename:myname].jpg
Adjust for other shells (eg don't double the % in bash).

This reads all the png images into memory first, before converting any, so is memory-intensive.
snibgo's IM pages: im.snibgo.com
Dread Knight
Posts: 3
Joined: 2015-04-25T20:34:09-07:00
Authentication code: 6789
Contact:

Re: batch png to jpg drop in conversion

Post by Dread Knight »

Thanks, though I'll need something that's not memory-intensive as my image collection is quite huge :D hence why I want to compress it... hmm
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch png to jpg drop in conversion

Post by snibgo »

mogrify works one file at a time:

Code: Select all

mogrify -format jpg *.png
If you want to traverse directory tree, you'll need a script.
snibgo's IM pages: im.snibgo.com
Dread Knight
Posts: 3
Joined: 2015-04-25T20:34:09-07:00
Authentication code: 6789
Contact:

Re: batch png to jpg drop in conversion

Post by Dread Knight »

Understood, thanks.
Post Reply