Using convert or mogrify - recursive sub-directories

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
Posts: 1
Joined: 2014-07-04T13:46:18-07:00
Authentication code: 6789

Using convert or mogrify - recursive sub-directories

Post by mc2028 » 2014-07-04T14:14:54-07:00

I have a stash of *.tif files that need to be converted to *.pdf's, but they're unfortunately in a complex tree of directories and subdirectories (some as deep as 5-6). I've tried using find in conjunction with mogrify but without luck:

find ./ -name "*.tif" -exec mogrify -format pdf *.tif {} \;

I keep getting "find: No match" When I only use "find ./ -name "*.tif," everything is just fine (it lists all the files). So I'm not sure what's going on. I've been able to use find with other commands but never with mogrify or convert.

Any help greatly appreciated.

User avatar
Posts: 23393
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using convert or mogrify - recursive sub-directories

Post by fmw42 » 2014-07-04T16:03:44-07:00

Neither one can be use that way as I understand it. Both do different things. mogrify can deal with only one folder at a time. convert cannot use wildcards for both input and output. However, you can write a script loop over each image in any directory to process with convert (or mogrify). But that is OS dependent. It appears you are on Unix.This has been discussed many time on this forum, so search the forum for "recursive".

Here are a few results of such search:
viewtopic.php?f=1&t=23424&p=98519&hilit ... ive#p98555
viewtopic.php?f=1&t=23424&p=98519&hilit ... ive#p98565
viewtopic.php?f=1&t=23424&p=98519&hilit ... ive#p98595
viewtopic.php?f=1&t=23424&p=98519&hilit ... ive#p98600
viewtopic.php?f=1&t=23424&p=98519&hilit ... ive#p98622
viewtopic.php?f=1&t=17774&p=67250&hilit ... ive#p67250

see mogrify and alternates to process multiple directories at:

User avatar
Posts: 1
Joined: 2018-06-16T10:54:55-07:00
Authentication code: 1152

Re: Using convert or mogrify - recursive sub-directories

Post by Gus » 2018-06-16T11:10:04-07:00

In my case, I have achieved the goal with the following instruction in a CMD window in the root folder:

Code: Select all

FOR /R %f IN (*.jpg) DO mogrify -verbose -quality 96 "%f"
My goal was to reduce the size of thousands of images organized in hundreds of folders (I added -verbose to follow the process) by reducing JPEG quality a little bit.

It worked! :D

Post Reply