I know convert changes from one image format to another. mogrify can resize and scale multiple images also. But how can I modify all images inside a directory, including the sub-directories. Like for example change every image inside a folder and its sub-folders from one format png to another format jpg, or resize all pictures in a folder and its sub-folders to a desire one?
Asked
Active
Viewed 567 times
2
Zanna
- 69,223
- 56
- 216
- 327
Luis Alvarado
- 209,003
- 167
- 543
- 707
1 Answers
2
Since mogrify accepts a list of files, separated by line breaks, you can do this:
mogrify -equalize $(find -iname '*.png')
I use equalize as an example, but the important bit is the last one.
- The file name can be any expression that prints out a list of files, i use
find -iname '*.png'as an example. You can play around with thefindcommand until it give you the list of files you want.
It's important that whatever command you put in $() returns a list of files with their correct path. ls -Ra will just return the file name. The output of find | grep png on the other hand looks like this:
./Webcam/lenovo-maverick-20110101-1.png
./lenovo-maverick-20110101-2.png
./lenovo-maverick-20110101-1.png
Where . means "the current working directory".
Stefano Palazzo
- 85,787
- 45
- 210
- 227
-
1Why won't you use `find -exec`? – Elazar Leibovich Jan 01 '11 at 22:34
-
@Elazar never mind me :-) I've changed the answer completely now, there's a much easier way. – Stefano Palazzo Jan 01 '11 at 22:37
-
`s/$(find|grep png)/$(find -iname '*.png')/` and you're OK. – Elazar Leibovich Jan 01 '11 at 22:45
-
1Nice. i knew how to use find but never occured to me. Thank god for Linux. – Luis Alvarado Jan 01 '11 at 22:54
-
Done that, thank you very much @Elazar. As I said, it's good to play around with `find`, you can have much more granular control over what files are modified, for example, excluding all that contain "-thumbnail" or something like that. – Stefano Palazzo Jan 01 '11 at 22:55
-
Add quotes to make it work with spaces in filenames: `mogrify -equalize "$(find -iname '*.png')"` – Volker Siegel Apr 15 '16 at 05:44