Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

When you rename files into a different, most of the times it does not work. But, suppose you have a .png file, you can just rename "image.png" to "image.jpeg" or "image.gif", it automatically gets converted to the other format and works perfectly fine. Is there some similarity between these formats which allows this to be done? I had noticed this a few years back, and got interested when I was trying too convert a .dvi file to a .pdf file, a just renaming it worked.

share|improve this question
    
png to jpeg doesn't work in my system. The format is completely different. Are you sure that happens in ubuntu!! :O –  Web-E Jul 22 '12 at 5:37
    
No, there is absolutely no similarity whatsoever between gif and jpeg. You cannot simply rename any of the files to convert them, except by using an app which does it for you. For example, saving a gif file as jpeg in something like Gimp will convert it; renaming it on a command line will not. –  Marty Fried Jul 22 '12 at 5:38
    
I am renaming from the command line, and yes, it does work. I am using Ubuntu only, and I remember it working even on Windows. –  asymptotically Jul 22 '12 at 5:40
    
What about dvi and pdf? Are there similarities between those two? –  asymptotically Jul 22 '12 at 5:45
1  
NO , it doesn't get converted by Simply renaming, since .jpg .jpeg .png have same Default Image Viewer , it opens them. Try changing the Default Viewer for .jpg or .png and try opening them , you will get the difference. –  atenz Jul 22 '12 at 5:52

2 Answers 2

up vote 11 down vote accepted

This is what probably happens. The application designated to open files with the file types you mention, is the same across all of those. .gif, .jpg, .png: these are all handled by EOG (GNOME's Eye Of Gnome). I suspect this application does not determine the file type based on the extension, rather it seeks for the magic number.

Note that the behavior of EOG may very well be exceptional, and also beware that no actual conversion is done. It's just that Linux applications tend to rely on different detection methods than file extensions, though many modern desktops actually look for the file extension to determine what application to open, since this method is probably quicker.

This all may apply to Ubuntu, Windows is a completely different story. Explorer practices a behavior by default that cuts off the file extension from the filename. This way, a file named "document.pdf" will show as "document", and renaming it to "document.dvi" will actually be processed as "document.dvi.pdf". Viruses sometimes exploit this "feature" by making the user believe they are opening a .jpg, while in reality they are being tricked into running a malicious exe!

To be really sure about filetypes, there is a command called file that shows you detailed file information.

From my personal experience, I can tell that, at least on my system, EOG cannot be tricked into recognizing a renamed image file. You must be doing something different than I do.

share|improve this answer
    
This worked even on Windows, and I think it does get converted. Once, I was trying the convert a bmp to jpeg to reduce the file size, and just renaming it worked. And before I made EOG the default application, I was using Gwenview (KDE). And anyway, the default application shouldn't have any effect on file management, should it? –  asymptotically Jul 22 '12 at 5:44
    
I used Windows XP, and I always had the file type shown. Anyway, I guess that does make sense. Thanks! And I did not know about that Windows feature of cutting file extensions ... Good thing I use Ubuntu now ;) And thanks for the information about magic numbers. I knew what they were, but didn't know they were called "magic numbers" –  asymptotically Jul 22 '12 at 8:35
    
neither windows nor ubuntu convert files just by renaming them - an overly smart program is just ignoring the extension completely when loading the file. –  ImaginaryRobots Jul 31 '12 at 22:28

Renaming .png files to .jpeg and .gif working because, the program associated to open those files are same and when it sees the extensions it can open, it simply opens them, because those are all image files and the program can open it.

The default program is EOG (Eye of Gnome) as other answerer says. If you even remove the extension, it can open them also.

As for the dvi and pdf, also both file types are opened by the same program, which is called evince. So, same things happening here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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