Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I know convert changes from a 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.

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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 the find command 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".

share|improve this answer
1  
Why won't you use find -exec? –  Elazar Leibovich Jan 1 '11 at 22:34
    
@Elazar never mind me :-) I've changed the answer completely now, there's a much easier way. –  Stefano Palazzo Jan 1 '11 at 22:37
    
s/$(find|grep png)/$(find -iname '*.png')/ and you're OK. –  Elazar Leibovich Jan 1 '11 at 22:45
1  
Nice. i knew how to use find but never occured to me. Thank god for Linux. –  Luis Alvarado Jan 1 '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 1 '11 at 22:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.