{"id":16125717,"url":"https://github.com/dy/image-output","last_synced_at":"2025-05-09T00:05:42.961Z","repository":{"id":57272087,"uuid":"157329481","full_name":"dy/image-output","owner":"dy","description":"Output image to a file, stream, canvas, console, buffer or any other destination","archived":false,"fork":false,"pushed_at":"2025-01-18T21:32:16.000Z","size":54,"stargazers_count":18,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-09T00:05:34.904Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/dy.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-11-13T06:10:21.000Z","updated_at":"2025-01-18T21:32:18.000Z","dependencies_parsed_at":"2022-09-11T13:20:30.059Z","dependency_job_id":null,"html_url":"https://github.com/dy/image-output","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-output","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-output/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-output/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dy%2Fimage-output/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dy","download_url":"https://codeload.github.com/dy/image-output/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253166518,"owners_count":21864476,"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":"2024-10-09T21:30:59.105Z","updated_at":"2025-05-09T00:05:42.913Z","avatar_url":"https://github.com/dy.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# image-output [![Build Status](https://travis-ci.org/dy/image-output.svg?branch=master)](https://travis-ci.org/dy/image-output) [![unstable](https://img.shields.io/badge/stability-unstable-green.svg)](http://github.com/badges/stability-badges)\n\nOutput image data to a destination: file, canvas, console, stdout, ImageData etc.\n\n## Usage\n\n[![$ npm install image-output](http://nodei.co/npm/image-output.png?mini=true)](http://npmjs.org/package/image-output)\n\n```js\nvar output = require('image-output')\n\n// create chess pattern png from raw pixels data\noutput({\n\tdata: [0,0,0,1, 1,1,1,1, 1,1,1,1, 0,0,0,1],\n\twidth: 2,\n\theight: 2\n}, 'chess.png')\n```\n\n## API\n\n### `output(source, destination?, options?)`\n\nOutput pixel data `source` to a `destination` based on `options`. Undefined destination displays image to console/stdout. The operation is done in sync fashion.\n\n#### `source`\n\nShoud be an actual image data container, one of:\n\n* _Canvas_, _Context2D_, _WebGLContext_\n* _ImageData_\n* _Object_ `{data: Uint8Array, width, height}`\n* DataURL or base64 string\n* _Image_, _Video_, _ImageBitmap_ with resolved data\n* _Array_, _Array_ of _Arrays_, _Uint8Array_, _FloatArray_ with raw pixels\n* _ArrayBuffer_, _Buffer_\n* _Ndarray_\n\nHandy for that purpose is [`image-pixels`](https://ghub.io/image-pixels):\n\n```js\nvar pixels = require('image-pixels')\noutput(await pixels('image.png'), 'image-copy.png')\n```\n\n#### `destination`\n\nCan be any image output destination:\n\nType | Meaning\n---|---\n_String_ | File to create or path, in node. If includes extension, mimeType is detected from it.\n_Canvas2D_, _Context2D_ | Render pixel data into a canvas. Canvas is resized to fit the image data. To avoid resizing, use `options.clip` property.\n`document`, _Element_ | Create a canvas with diff data in document or element.\n`console` | Display image to console in browser or to terminal in node.\n_Array_ / _FloatArray_ | Write pixel data normalized to [0..1] range to a float-enabled array.\n_UintArray_ | Put pixel data to any unsigned int array.\n_Buffer_ / _ArrayBuffer_ | Put pixel data into a buffer, possibly encoded into target format by `options.type`.\n_Ndarray_ | Write pixel data into an [ndarray](https://ghub.io/ndarray).\n_ImageData_ | Put data into _ImageData_ instance, browser only.\n_Object_ | Create `data`, `width` and `height` properties on an object.\n_Function_ | Call a function with _ImageData_ as argument.\n_Stream_ | Send data to stream, eg. `process.stdout`.\n\u003c!--_WebStream_ | TODO. Send data to stream, eg. `process.stdout`.--\u003e\n\n#### `options`\n\nProperty | Meaning\n---|---\n`width`, `height` | Explicitly indicate input data shape (columns, rows), if input has no dimensions info.\n`type` / `mime` | Encode into target type, by default detected from file extension. By default `image/png`.\n`quality` | Defines encoding quality, 0..1, optional. By default 1.\n`...rest` | Rest of options is passed to encoder.\n\u003c!-- `clip` | Defile clipping area rectangle from the initial data to save. --\u003e\n\n## Customize color palette in terminal\n\nYou can choose color palette with flags or environment variable `FORCE_COLOR=0123`\n```\nnode ./script.js --no-color\nnode ./script.js --color\nnode ./script.js --color=256\nnode ./script.js --color=16m\n```\n\n## Related\n\n* [image-equal](https://ghub.io/image-equal) − compare if two images are equal.\n* [image-pixels](https://ghub.io/image-pixels) − load image data from any source.\n* [image-encode](https://ghub.io/image-encode) − encode image data into one of the target formats.\n\n## Similar\n\n* [save-pixels](https://ghub.io/save-pixels) − output ndarray with image pixels to a file.\n* [terminal-image](https://ghub.io/terminal-image) − print image to a terminal.\n\n## License\n\n© 2018 Dmitry Iv. MIT License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fimage-output","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdy%2Fimage-output","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdy%2Fimage-output/lists"}