I have many webp format images in a folder but with .jpg
extension like
abc-test.jpg
It's a webp
format image. I want it to convert in .png
format with same name for that I have used this command and it worked
find . -name "*.jpg" -exec dwebp {} -o {}.png \;
It converted all webp
images to .png
but the issue is it's saving images like this:
abc-test.jpg.png
But my requirement is to save it without .jpg
extension like
abc-test.png
If you have many to convert/rename, I would recommend you use GNU Parallel and not only get them converted faster by doing them I parallel, but also take advantage of the ability to modify filenames.
The command you want is:
parallel dwebp {} -o {.}.png ::: *.jpg
where the {.}
means "the filename without the original extension".
If you want to recurse into subdirectories too, you can use:
find . -name "*.jpg" -print0 | parallel -0 dwebp {} -o {.}.png
If you want a progress meter, or an "estimated time of arrival", you can add --progress
or --eta
after the parallel
command.
If you want to see what GNU Parallel would run, without actually running anything, add --dry-run
.
I commend GNU Parallel to you in this age where CPUs are getting "fatter" (more cores) rather than faster.
Tested on Linux Ubuntu 20.04
This question is the top hit for the Google search of "linux convert .webp image to png". Therefore, for anyone stumbling here and just wanting that simple answer, here it is:
# 1. Install the `webp` tool
sudo apt update
sudo apt install webp
# 2. Use it: convert in.webp to out.png
dwebp in.webp -o out.png
Done! You now have out.png
.
dwebp
from the question itself
I did it with short oneliner that does not require parallel
to be installed in the system
for x in `ls -1 *.jpg`; do dwebp {} -o ${x%.*}.png ::: $x; done
And this works for current directory
I would try to amend the @mark-setchell recursive solution so it would look like this:
for x in `find . -name "*.jpg"`; do dwebp {} -o ${x%.*}.png ::: $x; done
The ${x%.*}
part is the one requiring a word of explanation here - it tells bash to take .
and everything after the dot from the x
variable.
It is prone to misbehave for names with more dots as I did not check if regex here is lazy or greedy - the answer can be tuned further therefore.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With