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.


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:

for NAME in $(ls *.png); do

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

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


  • 1
    I know that this can probably be accomplished quite more easily with a single line using ´find´ with ´exec´ and such, but I'm not a 'scripter' at all, so anyone should feel free to edit my answer and add a shorter command, if you wish.
    – luri
    Mar 4 '11 at 21:55
  • This answer was of great help when debugging a javascript driven image download script. Thanks!! :) Sep 10 '15 at 10:24
  1. Remove the file extension, and Eye of Gnome will be able to view your images. For example, the image below is a file with no extension:

    image appears fine

    This, however may be not useful for you if you wish the files to have the correct extension.

  2. To correct the extensions instead, you may be interested in Phatch, which will allow you to perform batch process for renaming and several other tasks.

    Phatch dialog

    Rename action in Phatch

Additionally you may be interested in the Nautilus Scripts Pack which makes the image conversion as easy as a single click.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.