3

I was wondering about the following;

I use the following command to find .jpg files in (sub)directorys and convert (mogrify) them to .webp files.

find . -name '*.jpg' -execdir mogrify -format webp {} \;

In this case: file.jpg becomes file.webp (and .jpg is kept).

What I want is:

Example: file.jpg becomes file.jpg.webp (and .jpg is kept).

  1. How can I modify my code that it will set .jpg.webp?
  2. Is there a code that checks if a file is already converted so it will pass, UNLESS the original .jpg file is newer?

Thanks in advance!

2

Your first question can be addressed easily enough:

find . -iname '*.jpg' -exec  convert '{}' -format webp '{}'.webp \;

This will:

  1. Recursively find all .jpg files, as in your example
  2. Convert each .jpg file to webp using convert rather than mogrify
  3. Use the naming convention you were after: 'filename.jpg.webp'

Tested nicely on my system...

References:

| improve this answer | |
  • Thanks for answering Q1. My result is this: 'find . -iname '*.jpg' | parallel --eta convert '{}' -format webp '{}'.webp \; – HRR Jul 20 '16 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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