Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imgtype

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imgtype

detect image file type

  • 0.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

imgtype

Image type Hint.

Usage

require! <[imgtype]> # only if use in nodejs imgtype(obj).then ({ext, mime}) -> ... # ext = null if can't figure it out

Mime mappaing

You can use imgtype.mime["..."] to get the mime type for a specific file extension, such as:

imgtype.mime.svg
imgtype.mime.jpg

Supported extensions include:

  • bmp: image/bmp
  • gif: image/gif
  • png: image/png
  • svg: image/svg+xml
  • tif: image/tiff
  • jpg: image/jpeg

Approach

Image file type can be detected throught the first two bytes of the file:

  • TIF
    • SU : 49 49
    • TU : 4D 4D
  • BMP : Qk : 42 4D
  • JPG : /9 : FF D8 FF EO ( Starting 2 Byte will always be same)
  • PNG : iV : 89 50 4E 47
  • GIF : R0 : 47 49 46 38
  • SVG
    • <?xml or <svg, with possibly space ahead.
    • PD : 3C 3F <?
    • PH : 3C 73 <s
    • ID : 20 3C <
    • IC : 20 20

While image files begin with these pattern, there might still be other file formats that begin with the same pattern. Furthermore, there might be exceptions for SVG files.

Thus, this should only be considered as a hint instead of a correct result.

License

MIT

FAQs

Package last updated on 05 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc