Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine an image's encoding

I have an image with a PNG extension.

I suspect it's not really a PNG though (I think it might be a GIF).

How can I confirm an image's encoding?

NB: A solution for Windows would be preferable

like image 605
BanksySan Avatar asked Feb 24 '17 12:02

BanksySan


3 Answers

on Linux, you can use file command

$ file branches.gif
branches.gif: PNG image data, 1257 x 782, 8-bit/color RGBA, non-interlaced

or ImageMagick part called identify

identify branches.gif
branches.gif PNG 1257x782 1257x782+0+0 8-bit sRGB 114KB 0.000u 0:00.000
like image 186
Quantim Avatar answered Oct 12 '22 12:10

Quantim


You need to do a quick check of the file's internals.

The first 8 bytes of a PNG image are always

137 80 78 71 13 10 26 10

It is vanishingly unlikely that a non-malicious non-PNG has the same 8 bytes.

like image 21
Malcolm McLean Avatar answered Oct 12 '22 11:10

Malcolm McLean


For windows open the file in a text editor, e.g. Sublime, and the first part should be the png magic number 89 50 4e 47 0d 0a 1a 0a.

like image 3
user8981408 Avatar answered Oct 12 '22 11:10

user8981408