Nth Permutation Mathematics


    1.7.1 • Public • Published


    Licence npm Issues Build Status

    Have you ever wished for the ability to retrieve image or video file attributes such as width, height, size, and mime type in Node without having to resort to external libraries such as ffprobe?

    Yeah, me too! This is why leather was created. At the moment, the only package that does something similar is image-size and while it does work well, it does not handle video formats.


    leather uses streams to read image and video files in byte-sized chunks. As soon attributes have been extracted, the stream will be closed. Some file formats have a well-defined fixed position in which these attributes can be found, in those cases, leather skips any bytes before that position and reads only the bytes needed to extract attributes directly.

    However, sometimes the byte offset of these attributes may vary, in these scenarios leather makes a best-effort attempt to read as few bytes as possible to get to the good stuff!


    Before leather, if you wanted to do something like this in Node you would need to install image-size to handle images and either use ffprobe directly or using some kind of wrapper package to handle video files.

    While I love ffprobe for its capabilities, setting up a cross-platform package requires some configuration. This package aims to solve that by steering clear of any command-line tools which makes it more portable.

    Node support

    Node version 12.20 and up are supported.


    Install the package locally using npm:

    npm install leather --save

    Or using yarn

    yarn add leather


    After installing the package, it can be imported using commonjs:

    const {attributes} = require('leather');

    Or using ES modules:

    import {attributes} from 'leather';

    Then, it can be called on supported image and video formats:

    // => {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}

    The width and height are pixel based. The size is the same as fs.stat. If the width or height could not be extracted, they will default to 0. The mime type is also returned if found, otherwise undefined.

    Using specific extractors

    If you are only using one or a few of the extractors, you can opt to require only the extractors you need, e.g. for jpg/jpeg using commonjs:

    const {attributes} = require('leather/extractors/jpg');
    // => {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}

    Or using ES modules:

    import {attributes} from 'leather/extractors/jpg';
    // => {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}

    Supported formats

    All supported image and video formats can be found in the table below:

    format extractor mime type
    bmp bmp image/bmp
    dds dds image/vnd.ms-dds
    gif gif image/gif
    icns icns image/x-icns
    ico ico image/x-icon
    cur ico image/x-icon
    j2c j2c image/x-jp2-codestream
    jp2 j2c image/jp2
    jpg jpg image/jpeg
    ktx ktx image/ktx
    png png image/png
    pfm pnm image/x-portable-bitmap
    pam pnm image/x-portable-bitmap
    pbm pnm image/x-portable-bitmap
    pgm pnm image/x-portable-bitmap
    ppm pnm image/x-portable-bitmap
    psd psd image/vnd.adobe.photoshop
    svg svg image/svg+xml
    tiff tiff image/tiff
    webp webp image/webp
    xpm xpm image/x-xpixmap
    xbm xbm image/x-xbitmap
    fit fit image/fits
    cel cel application/octet-stream
    hdr hdr text/x-mpsub
    avi avi video/x-msvideo
    fli fli video/x-flic
    flc fli video/x-flic
    flv flv video/x-flv
    mng png video/x-mng
    mp4 mp4 video/mp4
    mov mp4 video/quicktime
    ogv ogv video/ogg
    mkv webm video/x-matroska
    webm webm video/webm
    wmv wmv video/x-ms-wmv


    View releases.

    Credits and other resources that saved my soul


    npm i leather

    DownloadsWeekly Downloads






    Unpacked Size

    68.3 kB

    Total Files


    Last publish


    • sidofc