Skip to content
forked from wbond/puremagic

A pure lua module for detecting the mime type of a common image file based on the contents - inspired by libmagic

License

Notifications You must be signed in to change notification settings

cgwxyz/puremagic

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

puremagic

A pure lua module that detects the mime type of common image file based on their contents, only PNG/GIF/WEBP/JPEG supported.

Tested on Lua 5.1 and Luajit 2.0.

Version

The current version is: 1.0.1

Usage

Basic usage:

local puremagic = require('puremagic')
local mimetype = puremagic.via_path('/path/to/file')

When dealing with temp files, you may want to pass the original filename in case the extension is needed:

local puremagic = require('puremagic')
local mimetype = puremagic.via_path('/var/tmp/xyz', 'test.xlsx')

If you have the contents of the file in memory, you can provide those plus the filename:

local content = '#!/bin/bash\n'
local puremagic = require('puremagic')
local mimetype = puremagic.via_content(content, 'test.sh')

Supported Mime Types

The following mime types are detected:

Images

File type Mime type
GIF image/gif
JPEG image/jpeg
PNG image/png
webp image/webp

Running Tests

lua tests.lua

or

luajit tests.lua

About

A pure lua module for detecting the mime type of a common image file based on the contents - inspired by libmagic

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Lua 100.0%