{"id":28372838,"url":"https://github.com/jimp-dev/bmp-ts","last_synced_at":"2025-06-25T12:31:35.932Z","repository":{"id":35123264,"uuid":"209640553","full_name":"jimp-dev/bmp-ts","owner":"jimp-dev","description":"A pure typescript bmp encoder and decoder","archived":false,"fork":false,"pushed_at":"2024-03-24T03:26:12.000Z","size":1081,"stargazers_count":17,"open_issues_count":18,"forks_count":6,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-05T16:46:59.081Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jimp-dev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2019-09-19T20:12:32.000Z","updated_at":"2025-05-18T21:04:19.000Z","dependencies_parsed_at":"2024-06-21T05:43:50.806Z","dependency_job_id":"3ae6a9e3-0718-4286-8a36-c313c79c135b","html_url":"https://github.com/jimp-dev/bmp-ts","commit_stats":null,"previous_names":["hipstersmoothie/bmp-ts"],"tags_count":21,"template":false,"template_full_name":null,"purl":"pkg:github/jimp-dev/bmp-ts","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimp-dev%2Fbmp-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimp-dev%2Fbmp-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimp-dev%2Fbmp-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimp-dev%2Fbmp-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jimp-dev","download_url":"https://codeload.github.com/jimp-dev/bmp-ts/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jimp-dev%2Fbmp-ts/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261874421,"owners_count":23223116,"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":[],"created_at":"2025-05-29T16:41:21.466Z","updated_at":"2025-06-25T12:31:35.924Z","avatar_url":"https://github.com/jimp-dev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"200\" height=\"200\"\n    src=\"./logo.png\"\u003e\n  \u003ch1\u003ebmp-ts\u003c/h1\u003e\n  \u003cp\u003eA pure typescript \u003ccode\u003ebmp\u003c/code\u003e encoder and decoder.\u003c/p\u003e\n\u003c/div\n\n[![Codecov](https://img.shields.io/codecov/c/github/hipstersmoothie/bmp-ts.svg?style=for-the-badge)](https://codecov.io/gh/hipstersmoothie/bmp-ts)\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=for-the-badge)](https://github.com/prettier/prettier)\n\nSupports decoding and encoding in all bit depths (1, 4, 8, 16, 24, 32).\n\n## Install\n\n```sh\nnpm install bmp-ts\n```\n\n## Usage\n\n### Decoding\n\n`decode` will return an object that includes all the header properties of the `bmp` image file and the data. See header definition [below](#header).\n\n```js\nconst bmp = require('bmp-ts').default;\nconst bmpBuffer = fs.readFileSync('bit24.bmp');\nconst bmpData = bmp.decode(bmpBuffer);\n```\n\n#### Options\n\n- toRGBA - switch the output to big endian RGBA, making it compatible with other libraries like `pngjs`\n\n```js\nconst bmp = require('bmp-ts').default;\nconst bmpBuffer = fs.readFileSync('bit24.bmp');\nconst bmpData = bmp.decode(bmpBuffer, { toRGBA: true });\n```\n\n#### Supported Compression Methods\n\nCurrently compression is only supported during decoding. The following methods are implemented:\n\n- NONE - Most common\n- BI_RLE8 - Can be used only with 8-bit/pixel bitmap\n- BI_RLE4 - Can be used only with 4-bit/pixel bitmaps\n- BI_BIT_FIELDS - Huffman 1D - BITMAPV2INFOHEADER: RGB bit field masks, BITMAPV3INFOHEADER+: RGBA\n- BI_ALPHA_BIT_FIELDS - RGBA bit field masks - only Windows CE 5.0 with .NET 4.0 or later\n\n### Encoding\n\nTo encode an image all you need is a buffer with the image data, the height and the width. You can specify the bit depth of the output image by modifying `bitPP`. If you do not provide a value, the output image defaults to 24-bit.\n\nAll header fields are valid options to `encode` and will be encoded into the header.\n\n```js\nconst bmp = require('bmp-ts').default;\nconst fs = require('fs');\nconst bmpData = {\n  data, // Buffer\n  bitPP: 1 | 2 | 4 | 16 | 24 | 32, // The number of bits per pixel\n  width, // Number\n  height, // Number\n};\n\n// Compression is not supported\nconst rawData = bmp.encode(bmpData);\nfs.writeFileSync('./image.bmp', rawData.data);\n```\n\n## Header\n\n| Property        | Type    | Purpose                                                                                                |\n| --------------- | ------- | ------------------------------------------------------------------------------------------------------ |\n| fileSize        | number  | The size of the BMP file in bytes                                                                      |\n| reserve1        | number  | Reserved; actual value depends on the application that creates the image                               |\n| reserve2        | number  | Reserved; actual value depends on the application that creates the image                               |\n| offset          | number  | The offset, i.e. starting address, of the byte where the bitmap image data (pixel array) can be found. |\n| headerSize      | number  | The size of this header (12 bytes)                                                                     |\n| width           | number  | The bitmap width in pixels (unsigned 16-bit)                                                           |\n| height          | number  | The bitmap height in pixels (unsigned 16-bit)                                                          |\n| planes          | number  | The number of color planes, must be 1                                                                  |\n| bitPP           | number  | The number of bits per pixel                                                                           |\n| compress        | number  | The compression method being used. See the supported compression methods                               |\n| rawSize         | number  | The image size. This is the size of the raw bitmap data; a dummy 0 can be given for BI_RGB bitmaps.    |\n| hr              | number  | The horizontal resolution of the image. (pixel per metre, signed integer)                              |\n| vr              | number  | The vertical resolution of the image. (pixel per metre, signed integer)                                |\n| colors          | number  | The number of colors in the color palette, or 0 to default to 2n                                       |\n| importantColors | number  | The number of important colors used, or 0 when every color is important; generally ignored             |\n| palette         | Color[] | The colors used to render the image. only used for 1, 4, and 8 bitPP images                            |\n| data            | Byte[]  | The data in ABGR                                                                                       |\n\n### Color\n\nThe color palette is returned when decoding a 1, 4, or 8 bit image.\n\nColor Format:\n\n```json\n{\n  \"red\": 255,\n  \"green\": 255,\n  \"blue\": 255,\n  \"quad\": 255\n}\n```\n\nTo encode to 4 or 8 bit a color palette must be provided. 1 bit defaults to black and white but you can override this via palette.\n\n```js\nconst rawData = bmp.encode({\n  data,\n  bitPP: 8,\n  width,\n  height,\n  palette: [\n    { red: 255, green: 255, blue: 255, quad: 0 },\n    { red: 255, green: 255, blue: 0, quad: 0 },\n    { red: 255, green: 0, blue: 255, quad: 0 },\n    { red: 255, green: 0, blue: 0, quad: 0 },\n    { red: 0, green: 255, blue: 255, quad: 0 },\n    { red: 0, green: 255, blue: 0, quad: 0 },\n    { red: 0, green: 0, blue: 255, quad: 0 },\n    { red: 0, green: 0, blue: 0, quad: 0 },\n  ],\n});\n\nfs.writeFileSync('./image.bmp', rawData.data);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimp-dev%2Fbmp-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjimp-dev%2Fbmp-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjimp-dev%2Fbmp-ts/lists"}