13

I have a bunch of image files with the extension ".png", but I'm fairly sure some of them are actually JPEGs that were renamed to PNGs. As far as I know, simply renaming the file doesn't actually change the formatting, compression, etc., so how do I check which are formatted accordingly to their extensions?

Plus, does XnConvert actually convert the images' format?

  • Renaming a file/changing its extension is sort of like changing the label on the sugar container to "Salt". It has no effect on the contents but annoys the humans who have to use it. Try adding a .JPG extension to one of your PNG files (ie, change MYFILE.PNG to MYFILE.PNG.JPG or just MYFILE.JPG) to see if programs will open it. Or open the file in a text editor. If JPG, its first four charactes should be ÿØÿà. If PNG, the first four characters will be ‰PNG – Steve Rindsberg Jul 28 '20 at 14:40

2 Answers2

14

If you have either a Linux system, or WSL (on Windows) you could type

file myimagewithoutextension

Output:

myimagewithoutextension: JPEG image data, JFIF standard 1.01, resolution (DPI), density 96x96, segment length 16, baseline, precision 8, 768x576, frames 3

The file command completely ignores the file extension, but rather relies on information in the file header.

Alternatively, open the suspected PNG in Notepad. If it's truly a PNG, it will have ‰PNG on the first line. Jpeg's will have JFIF somewhere near the start.

enter image description here

Berend
  • 2,888
5

How do I check which are formatted accordingly to their extensions?

You can use ImageMagick for this. ImageMagick is available for Windows, Mac and Linux. You will typically want one of the "DLL" versions for Windows (not one of the "Static" versions).

Once installed, you can identify images with incorrect extensions with ex. magick identify file.ext:

Example

# Should be a .jpg, not a .png

magick identify it-kama-sutra.png it-kama-sutra.png JPEG 500x397 500x397+0+0 8-bit sRGB 37707B 0.000u 0:00.060

Should be a .gif, not a .png

magick identify giphy.png giphy.png[0] GIF 346x255 346x255+0+0 8-bit sRGB 256c 0.000u 0:00.062 giphy.png[1] GIF 346x255 346x255+0+0 8-bit sRGB 256c 0.000u 0:00.087 giphy.png[2] GIF 346x255 346x255+0+0 8-bit sRGB 256c 0.000u 0:00.092 [...] giphy.png[13] GIF 346x255 346x255+0+0 8-bit sRGB 256c 0.000u 0:00.237 giphy.png[14] GIF 346x255 346x255+0+0 8-bit sRGB 256c 0.000u 0:00.329 giphy.png[15] GIF 346x255 346x255+0+0 8-bit sRGB 256c 716527B 0.000u 0:00.336

Note that on Windows, you need to add magick.exe (magick) to your Windows path to use it without specifying its exact location (ex. C:\path\to\imagemagick\magick.exe).

Anaksunaman
  • 17,239