Below a python solution (script).
The script uses the imghdr module to recognize the file type. It will add the correct file extensions (if missing), of the following types:
rgb, gif, pbm, pgm, ppm, tiff, rast, xbm, jpeg, bmp, png
If the file already has a file extension, it will be skipped. In case the file is of an unknown file type (if it is damaged for example), the file is reported as "could not determine":
could not determine: /home/jacob/Bureaublad/picturetest/blub
The script:
#!/usr/bin/env python3
import os
import imghdr
import shutil
directory = "/path/to/pictures"
for name in os.listdir(directory):
# combining file+its directory:
file = directory+"/"+name
# only files without a dot are subject to renaming (else the file already has a file extension or is a hidden file):
if name.count(".") == 0:
# fetch the file extension from the file:
ftype = imghdr.what(file)
# if it is impossible to get the extension (if the file is damaged for example), the file(s) will be listed in the terminal window:
if ftype != None:
shutil.move(file, file+"."+ftype)
else:
print("could not determine: "+file)
Paste it into an empty file, save it as rename.py, set the directory to the pictures in the directory = "/path/to/pictures"
-line and run it by the command:
python3 /path/to/rename.py
Rename recursively
In case your images are not in a "flat" directory, but in a layered directory, use the version below. It will check (and repair if necessary) file extensions inside the file's current folder.
#!/usr/bin/env python3
import os
import imghdr
import shutil
directory = "/path/to/pictures"
for root, dirs, files in os.walk(directory):
for name in files:
file = root+"/"+name
if name.count(".") == 0:
ftype = imghdr.what(file)
if ftype != None:
shutil.move(file, file+"."+ftype)
else:
print("could not determine: "+file)
Best Answer
You should use find for finding all files you need.
And then you should rename files with name *.jpg_thumb to *_thumb.jpg by using:
Note that -50x50 is not a legal parameter for convert. You should use
-resize
parameter with value50x50
like in example above.