{"id":16548753,"url":"https://github.com/sidofc/leather","last_synced_at":"2025-03-21T10:31:55.438Z","repository":{"id":43073864,"uuid":"419312492","full_name":"SidOfc/leather","owner":"SidOfc","description":"A pure JS library for extracting image/video attributes such as width, height, size, and mime type","archived":false,"fork":false,"pushed_at":"2025-01-10T23:34:16.000Z","size":4790,"stargazers_count":12,"open_issues_count":1,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-11T12:09:44.479Z","etag":null,"topics":["dimensions","image","image-processing","mime-type","video"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/leather","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SidOfc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-20T12:04:25.000Z","updated_at":"2025-01-10T23:34:19.000Z","dependencies_parsed_at":"2024-06-19T09:25:42.053Z","dependency_job_id":"10e9d597-b8b9-4884-a36c-ac1f89cfaf37","html_url":"https://github.com/SidOfc/leather","commit_stats":null,"previous_names":[],"tags_count":34,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidOfc%2Fleather","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidOfc%2Fleather/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidOfc%2Fleather/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SidOfc%2Fleather/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SidOfc","download_url":"https://codeload.github.com/SidOfc/leather/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244130280,"owners_count":20402756,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dimensions","image","image-processing","mime-type","video"],"created_at":"2024-10-11T19:26:58.112Z","updated_at":"2025-03-21T10:31:55.419Z","avatar_url":"https://github.com/SidOfc.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Leather\n\n![Licence](https://img.shields.io/badge/license-MIT-E9573F.svg)\n[![npm](https://img.shields.io/npm/v/leather)](https://www.npmjs.com/package/leather)\n[![Issues](https://img.shields.io/github/issues/SidOfc/leather.svg)](https://github.com/SidOfc/leather/issues)\n[![Build Status](https://circleci.com/gh/SidOfc/leather.svg?style=shield)](https://app.circleci.com/pipelines/github/SidOfc/leather)\n\nHave you ever wished for the ability to retrieve image or video file attributes\nsuch as _width_, _height_, _size_, and _mime type_ in Node without having\nto resort to external libraries such as `ffprobe`?\n\nYeah, **me too!** This is why `leather` was created.\nAt the moment, the only package that does something similar is\n[`image-size`](https://www.npmjs.com/package/image-size)\nand while it does work well, it does not handle video formats.\n\n# How\n\n`leather` uses streams to read image and video files in byte-sized chunks.\nAs soon attributes have been extracted, the stream will be closed. Some file\nformats have a well-defined fixed position in which these attributes\ncan be found, in those cases, `leather` skips any bytes before that\nposition and reads only the bytes needed to extract attributes directly.\n\nHowever, sometimes the byte offset of these attributes may vary, in these\nscenarios `leather` makes a best-effort attempt to read as few bytes as\npossible to get to the good stuff!\n\n# Why\n\nBefore `leather`, if you wanted to do something like this in Node\nyou would need to install `image-size` to handle images and either\nuse `ffprobe` directly or using some kind of wrapper package to\nhandle video files.\n\nWhile I love `ffprobe` for its capabilities, setting up a cross-platform\npackage requires some configuration. This package aims to solve that\nby steering clear of any command-line tools which makes it more portable.\n\n# Node support\n\nStable Node versions from 16.x and up are tested.\n\n# Installation\n\nInstall the package locally using [`npm`](https://www.npmjs.com/):\n\n```shell\nnpm install leather --save\n```\n\nOr using [`yarn`](https://yarnpkg.com/)\n\n```shell\nyarn add leather\n```\n\n# Usage\n\nAfter [installing the package](#installation), it can be imported using commonjs:\n\n```javascript\nconst {readMediaAttributes} = require('leather');\n```\n\nOr using ES modules:\n\n```javascript\nimport {readMediaAttributes} from 'leather';\n```\n\nThen, it can be called on [supported image and video formats](#supported-formats):\n\n```javascript\nconsole.log(readMediaAttributes('cat.jpg'));\n\n// =\u003e {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}\n```\n\n## Buffer support\n\nStarting from version **2.1.0**, all `readMediaAttributes` methods also accept `Buffer`\ninstances in addition to file paths:\n\n```javascript\nconst buffer = fs.readFileSync('cat.png');\n\nconsole.log(readMediaAttributes(buffer));\n\n// =\u003e {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}\n```\n\nThe _width_ and _height_ are _pixel based_. The _size_ is the same as\n[`fs.stat`](https://nodejs.org/api/fs.html#fsstatpath-options-callback).\nIf the width or height could not be extracted, they will default to `0`.\nThe _mime_ type is also returned if found, otherwise `undefined`.\n\n## Using specific extractors\n\nIf you are only using one or a few of the extractors, you can opt to\nrequire only the extractors you need, e.g. for jpg/jpeg using commonjs:\n\n```javascript\nconst {readFileSync} = require('fs');\nconst {readMediaAttributes} = require('leather/extractors/jpg');\n\nconsole.log(readMediaAttributes('cat.jpg'));\nconsole.log(readMediaAttributes(readFileSync('cat.jpg')));\n\n// =\u003e {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}\n```\n\nOr using ES modules:\n\n```javascript\nimport {readFileSync} from 'fs';\nimport {readMediaAttributes} from 'leather/extractors/jpg';\n\nconsole.log(readMediaAttributes('cat.jpg'));\nconsole.log(readMediaAttributes(readFileSync('cat.jpg')));\n\n// =\u003e {width: 200, height: 200, size: 40000, mime: 'image/jpeg'}\n```\n\n# Supported formats\n\nAll supported image and video formats can be found in the table below:\n\n|  format  | extractor                      | mime type                     |\n|:---------|:-------------------------------|:------------------------------|\n| **bmp**  | [bmp](src/extractors/bmp.js)   | image/bmp                     |\n| **dds**  | [dds](src/extractors/dds.js)   | image/vnd.ms-dds              |\n| **gif**  | [gif](src/extractors/gif.js)   | image/gif                     |\n| **icns** | [icns](src/extractors/icns.js) | image/x-icns                  |\n| **ico**  | [ico](src/extractors/ico.js)   | image/vnd.microsoft.icon      |\n| **cur**  | [ico](src/extractors/ico.js)   | image/vnd.microsoft.icon      |\n| **j2c**  | [j2c](src/extractors/j2c.js)   | image/jp2                     |\n| **jp2**  | [j2c](src/extractors/j2c.js)   | image/jp2                     |\n| **jpg**  | [jpg](src/extractors/jpg.js)   | image/jpeg                    |\n| **ktx**  | [ktx](src/extractors/ktx.js)   | image/ktx                     |\n| **png**  | [png](src/extractors/png.js)   | image/png                     |\n| **apng** | [png](src/extractors/png.js)   | image/apng                    |\n| **pfm**  | [pnm](src/extractors/pnm.js)   | application/x-font-type1      |\n| **pam**  | [pnm](src/extractors/pnm.js)   | image/x-portable-arbitrarymap |\n| **pbm**  | [pnm](src/extractors/pnm.js)   | image/x-portable-bitmap       |\n| **pgm**  | [pnm](src/extractors/pnm.js)   | image/x-portable-graymap      |\n| **ppm**  | [pnm](src/extractors/pnm.js)   | image/x-portable-pixmap       |\n| **psd**  | [psd](src/extractors/psd.js)   | image/vnd.adobe.photoshop     |\n| **svg**  | [svg](src/extractors/svg.js)   | image/svg+xml                 |\n| **tiff** | [tiff](src/extractors/tiff.js) | image/tiff                    |\n| **webp** | [webp](src/extractors/webp.js) | image/webp                    |\n| **xpm**  | [xpm](src/extractors/xpm.js)   | image/x-xpixmap               |\n| **xbm**  | [xbm](src/extractors/xbm.js)   | image/x-xbitmap               |\n| **fit**  | [fit](src/extractors/fit.js)   | image/fits                    |\n| **cel**  | [cel](src/extractors/cel.js)   | application/octet-stream      |\n| **hdr**  | [hdr](src/extractors/hdr.js)   | image/vnd.radiance            |\n| **avi**  | [avi](src/extractors/avi.js)   | video/x-msvideo               |\n| **fli**  | [fli](src/extractors/fli.js)   | video/x-fli                   |\n| **flc**  | [fli](src/extractors/fli.js)   | video/x-fli                   |\n| **flv**  | [flv](src/extractors/flv.js)   | video/x-flv                   |\n| **mng**  | [png](src/extractors/png.js)   | video/x-mng                   |\n| **mp4**  | [mp4](src/extractors/mp4.js)   | video/mp4                     |\n| **m4v**  | [mp4](src/extractors/mp4.js)   | video/x-m4v                   |\n| **mov**  | [mp4](src/extractors/mp4.js)   | video/quicktime               |\n| **ogv**  | [ogv](src/extractors/ogv.js)   | video/ogg                     |\n| **mkv**  | [webm](src/extractors/webm.js) | video/x-matroska              |\n| **webm** | [webm](src/extractors/webm.js) | video/webm                    |\n| **wmv**  | [wmv](src/extractors/wmv.js)   | video/x-ms-wmv                |\n\n# Changelog\n\n[View releases.](https://github.com/SidOfc/leather/releases)\n\n# Credits and other resources that saved my soul\n\n- https://www.npmjs.com/package/image-size\n- http://www.fastgraph.com/help/avi_header_format.html\n- http://www.fastgraph.com/help/flic_header_format.html\n- https://docs.microsoft.com/en-us/previous-versions/ms779632(v=vs.85)\n- https://en.wikipedia.org/wiki/List_of_file_signatures\n- https://www.fileformat.info/format/tiff/egff.htm#TIFF.FO\n- http://netpbm.sourceforge.net/doc/#formats\n- https://www.garykessler.net/library/file_sigs.html\n- https://github.com/sannies/mp4parser/blob/c869d076e9cd42aba5a3e35d88827610dec6ca15/examples/src/main/java/com/google/code/mp4parser/example/GetHeight.java\n- https://developer.apple.com/library/archive/documentation/QuickTime/QTFF/QTFFChap1/qtff1.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidofc%2Fleather","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsidofc%2Fleather","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsidofc%2Fleather/lists"}