I need to create thumbnails from multiple .png files and would like to do this using ImageMagicks convert utility. To recursively find all files that are not thumbnails themselves, I am using the following call (split into two lines to make it readable):
find . -type f -name "*.png" -not -name "*thumb.png*"
-exec convert {} -thumbnail 200x200 {}.thumb.png ;`
But this would of course create a file named a.png.thumb.png when running it on a file called a.png. How could I remove the .png extension from the second {} parameter passed to convert?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The easiest way to do this is to pass the {} off to a shell like sh and have the shell do it:
find ...
-exec sh -c 'convert "$0" -thumbnail 200x200 "${0%.png}.thumb.png"' {} ;
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0