4

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!

1 Answer 1

3

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:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .