So I have a folder with thousands of image files, all of them saved as .jpg
.
The problem is that some of those files are actually PNG image files, so they don't open in a lot of programs, unless I manually change their extension to .png
. For example, the Ubuntu image viewer throws this error:
"Error interpreting JPEG image file (Not a JPEG file: starts with 0x89 0x50)"
I've already ran a hexdump of some of these files to confirm this error and it checks out.
I'm looking for a simple way to find all the files with the wrong extension among the other files and change their extension. How would I do this with a bash script for example? So far I have no idea. All help apreciated!
png file, you can just rename image. png to image. jpeg or image. gif , and it automatically gets converted to the other format and works perfectly fine.
Go to File>Automate>Batch. Choose the created set and action, and select the PNG images you want to convert. Photoshop will bulk convert all PNG images to JPEG on your Windows.
Open Finder and select the images you want to convert. Open them in Preview and then Select All. Go to "File" and choose "Export Selected Images". Choose the export format as PNG.
for f in *.jpg ; do
if [[ $(file -b --mime-type "$f") = image/png ]] ; then
mv "$f" "${f/%.jpg/.png}"
fi
done
This gets a list of .jpg
files, then for each calls the file
utility on it to get the mime type. If that's image/png
, then it renames the file using a string manipulation substitution.
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