Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if an extensionless image is png or jpeg

A while ago I saved some images generated by a web service so the file names are e.g 'ysauyft87ggsa67fgeg&w=1600'. I can open and manipulate these images OK, I'd just like to know what encoding they are (it's almost certainly png or jpeg). I've tried 'get info' in OSX, but it thinks the files are just text (even though it generates thumbnails correctly and I can view the images in preview). If I serve the images on a server they are delivered as 'application/octet-stream'.

How can I easily determine whether they are png or jpeg via the shell?

like image 884
wheresrhys Avatar asked Dec 27 '14 18:12

wheresrhys


People also ask

How do you make sure an image is a PNG?

Open the image you want to convert into PNG by clicking File > Open. Navigate to your image and then click “Open.” Once the file is open, click File > Save As. In the next window make sure you have PNG selected from the drop-down list of formats, and then click “Save.”

What does a PNG image look like?

A PNG file is an image saved in the Portable Network Graphic (PNG) format, commonly used to store web graphics, digital photographs, and images with transparent backgrounds. It is a raster graphic similar to a . JPG image but is compressed with lossless compression and supports transparency.

How can you tell if an Iphone photo is JPEG?

Start by navigating to the location of the document, video, or image, and then perform a Haptic Touch gesture (long-press) on the item. On the menu that pops up, tap Info. You can then see the file format listed next to the file name.


2 Answers

The "magic code" for a

  • PNG file should begin with 89 50 4E 47 0D 0A 1A 0A
  • JPEG files begin with FFD8 and end with FFD9
like image 109
ErstwhileIII Avatar answered Oct 08 '22 01:10

ErstwhileIII


Three methods:

  • Open a file in a Hex editor (or just a binary file viewer). PNG files start with 'PNG', .jpg files should have 'exif'or 'JFIF' somewhere in the beginning.
  • Use file command: https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/file.1.html For example: file 'ysauyft87ggsa67fgeg&w=1600'
  • Use identify file like torazaburo wrote in the comments (part of imagemagick lib)
like image 21
ZalewaPL Avatar answered Oct 08 '22 02:10

ZalewaPL