I use this script to convert all the .png
files in a directory to .jpg
files. If I want to convert not just png files, but also tif, gif and bmp files into jpg, how this script can be modified?
#!/bin/bash
for f in *.png ; do
convert "$f" -resize 50% "${f%.*}.jpg"
done
Just add the exensions you want to process; for example:
for f in *.png *.tif *.gif; do
or just:
for f in *.{png,tif,gif}; do
another approach could be: find every image file in a directory or a tree of folders and convert them to jpg except if the image is already a jpg file ; for example (not tested):
find . -exec bash -c 'file "$1" | grep "image data" | grep -iv JPEG && convert "$1" -resize 50% "${1%.*}.jpg"' {} {} \;
for f in *.{png,tif,gif,bmp}; do
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.