Ubuntu – EOG (Image Viewer) fails to open gif files with incorrect png extension – how can I solve this

command lineeogfile format

I have a bunch of files that have .png extension. However, some of them are actually gif files. I can open any of the files with gimp or view them in firefox, but when I try to open them with the Eye of Gnome viewer, it gives an error

Could not load image: Fatal error reading PNG image file: Not a PNG file

Is there:

  1. Another image viewer that can open files with incorrect extensions that I could use as default? It would need to have the ability to zoom in and out on images, and scroll through all the images in a folder via arrow keys.
  2. An automated way to rename the files that are actually gif files to the correct extensions?

Choice 2 is preferred, but I don't know how to tell what type they are. I would be able to put together a Bash script to do the renaming if there is a command that could tell me the file type.

Best Answer

If you use (from command line or within a script... if you need the script just ask ;) ) the command file thisimage.png, it will tell you what image format you actually have.... Then you can rename accordingly...

This is a sample of what I get with a file with incorrect file extension .png which is really a jpg file:

user@computer:$ file logo.png
logo.png: JPEG image data, JFIF standard 1.01 

Edit: Oh, ok, I was lazy before... Here's an script that will rename actual gif files that are named with .png extension to their correct extension .gif:

#!/bin/bash
for NAME in $(ls *.png); do

if [ "$(file $NAME|grep GIF)" ]; then

echo "Renaming ${NAME} to ${NAME%.*}.gif"
mv ${NAME} ${NAME%.*}.gif

fi

done
Related Question