Code Monkey home page Code Monkey logo

nim-imghdr's Introduction

About

nim-imghdr is a Nim module for determining the type of an image from a given file, filename, or sequence of bytes. It can detect many common image formats. nim-imghdr is a port of Python's imghdr module.

Usage:

testImage(file : File)
testImage(filename : string)
testImage(data : seq[int8])

nim-imghdr can also be used as a command line program:

imghdr [filename1] [filename2] ...

List of detected formats:

  • PNG (Portable Network Graphics) format - ImageType.PNG
  • JPEG (Joint Photographic Experts Group) format (either JFIF or Exif) - ImageType.JPEG
  • GIF (Graphics Interchange Format) format - ImageType.GIF
  • TIFF (Tagged Image File Format) format - ImageType.TIFF
  • SVG (Scalable Vector Graphics) format - ImageType.SVG
  • SGI (Silicon Graphics workstation) format - ImageType.RGB
  • PBM (portable bitmap) format - ImageType.PBM
  • PGM (portable graymap) format - ImageType.PGM
  • PPM (portable pixmap) format - ImageType.PPM
  • PAM format - ImageType.PAM
  • BMP (bitmap) format - ImageType.BMP
  • XMB (X10 or X11 bitmap) format - ImageType.XMB
  • Rast (Sun raster) format - ImageType.Rast
  • CRW (Canon camera RAW) format - ImageType.CRW
  • CR2 (Canon camera RAW 2) format - ImageType.CR2
  • MRW (Minolta camera RAW) format - ImageType.MRW
  • X3F (Sigma camera RAW) format - ImageType.X3F
  • WEBP format - ImageType.WEBP
  • XCF (GIMP native) format - ImageType.XCF
  • GKSM (Graphics Kernel System) format - ImageType.GKSM
  • PM (XV image) format - ImageType.PM
  • FITS (Flexible Image Transport System) format - ImageType.FITS
  • XPM (X PixMap 1 and 3) format - ImageType.XPM
  • XPM2 (X PixMap 2) format - ImageType.XPM2
  • PS (PostScript) format - ImageType.PS
  • Xfig format - ImageType.Xfig
  • IRIS format - ImageType.IRIS
  • SPIFF (Still Picture Interchange File Format) format - ImageType.SPIFF
  • GEM (GEM Raster) format - ImageType.GEM
  • Amiga icon format - ImageType.Amiga
  • TIB (Acronis True Image) format - ImageType.TIB
  • JB2 (JBOG2) format - ImageType.JB2
  • CIN (Kodak Cineon) format - ImageType.CIN
  • PSP (Corel Paint Shop Pro) format - ImageType.PSP
  • EXR (OpenEXR) format - ImageType.EXR
  • CALS (CALS raster bitmap) format - ImageType.CALS
  • DPX (Society of Motion Picture and Television Engineers Digital Picture Exchange image) format - ImageType.DPX
  • SYM (Windows SDK graphics symbol) format - ImageType.SYM
  • SDR (SmartDraw Drawing) format - ImageType.SDR
  • IMG (Img Software Set Bitmap) format - ImageType.IMG
  • ADEX (ADEX Corp. ChromaGraph Graphics Card Bitmap Graphic) format - ImageType.ADEX
  • NITF (National Imagery Transmission Format) format - ImageType.NITF
  • BigTIFF (Big Tagged Image File Format; TIFF > 4 GB) format - ImageType.BigTIFF
  • GX2 (Show Partner graphics) format - ImageType.GX2
  • PAT (GIMP pattern) format - ImageType.PAT
  • CPT (Corel Photopaint) format - ImageType.CPT
  • SYW (Harvard Graphics symbol graphic) format - ImageType.SYW
  • DWG (generic AutoCAD drawing) format - ImageType.DWG
  • PSD (Photoshop image) format - ImageType.PSD
  • FBM (fuzzy bitmap) format - ImageType.FBM
  • HDR (Radiance High Dynamic Range image) format - ImageType.HDR
  • MP (Monochrome Picture TIFF bitmap) format - ImageType.MP
  • DRW (generic drawing) format - ImageType.DRW
  • Micrografx (Micrografx vector graphics) format - ImageType.Micrografx
  • PIC (generic picture) format - ImageType.PIC
  • VDI (Ventura Publisher/GEM VDI Image Format Bitmap) format - ImageType.VDI
  • ICO (Windows icon) format - ImageType.ICO
  • JP2 (JPEG-2000) format - ImageType.JP2
  • YCC (Kodak YCC image) format - ImageType.YCC
  • FPX (FlashPix) format - ImageType.FPX
  • DCX (Graphics Multipage PCX bitmap) format - ImageType.DCX
  • ITC format - ImageType.ITC
  • NIFF (Navy Image File Format) format - ImageType.NIFF
  • WMP (Windows Media Photo) format - ImageType.WMP
  • BPG format - ImageType.BPG
  • FLIF format - ImageType.FLIF
  • PDF (Portable Document Format) format - ImageType.PDF
  • Unknown format - ImageType.Other

License

nim-imghdr is released under the MIT open source license.

nim-imghdr's People

Contributors

nigredo-tori avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

nim-imghdr's Issues

Return a ImageType enum instead of string

This is a pretty cool module! It would be awesome if you could change the testImage functions to return an ImageType enum instead of a string:

type
  ImageType {.pure.} = enum
    JPG, PNG, ...

Overflow in int2ascii

Crashes in SPIFF test when the bytes with values of 0x10 and greater are read.

Traceback (most recent call last)
my_module.nim(21)        isSupportedImage
imghdr.nim(520)          testImage
imghdr.nim(513)          testImage
imghdr.nim(580)          testImage
imghdr.nim(294)          testSPIFF
imghdr.nim(84)           ==
imghdr.nim(77)           int2ascii
system.nim(2536)         sysFatal

Unhandled exception: value out of range: -121

The offending image is in the attached archive (be careful - it crashes a lot of other software)

test.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.