{"id":13426013,"url":"https://github.com/sindresorhus/terminal-image","last_synced_at":"2025-05-14T03:06:40.732Z","repository":{"id":37550438,"uuid":"132634471","full_name":"sindresorhus/terminal-image","owner":"sindresorhus","description":"Display images in the terminal","archived":false,"fork":false,"pushed_at":"2025-01-03T22:00:03.000Z","size":642,"stargazers_count":1004,"open_issues_count":5,"forks_count":27,"subscribers_count":8,"default_branch":"main","last_synced_at":"2025-05-07T09:32:12.744Z","etag":null,"topics":["cli-utility","image","nodejs","npm-package","terminal-image"],"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/sindresorhus.png","metadata":{"files":{"readme":"readme.md","changelog":null,"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,"zenodo":null},"funding":{"github":"sindresorhus","open_collective":"sindresorhus","buy_me_a_coffee":"sindresorhus","custom":"https://sindresorhus.com/donate"}},"created_at":"2018-05-08T16:14:22.000Z","updated_at":"2025-04-29T15:58:40.000Z","dependencies_parsed_at":"2025-04-10T17:18:33.866Z","dependency_job_id":"15c0cf30-12b6-4f57-b46c-ac3a65385506","html_url":"https://github.com/sindresorhus/terminal-image","commit_stats":{"total_commits":33,"total_committers":6,"mean_commits":5.5,"dds":"0.36363636363636365","last_synced_commit":"c0552d014ec965bc64ec0c9fc78a90d31ced62e2"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fterminal-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fterminal-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fterminal-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sindresorhus%2Fterminal-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sindresorhus","download_url":"https://codeload.github.com/sindresorhus/terminal-image/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254059500,"owners_count":22007768,"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":["cli-utility","image","nodejs","npm-package","terminal-image"],"created_at":"2024-07-31T00:01:24.253Z","updated_at":"2025-05-14T03:06:40.665Z","avatar_url":"https://github.com/sindresorhus.png","language":"JavaScript","funding_links":["https://github.com/sponsors/sindresorhus","https://opencollective.com/sindresorhus","https://buymeacoffee.com/sindresorhus","https://sindresorhus.com/donate"],"categories":["Packages","JavaScript","Repository","包","Command-line utilities","目录","Node.js / JavaScript 🟨"],"sub_categories":["Command-line utilities","Command-line Utilities","命令行工具","命令行实用工具"],"readme":"# terminal-image\n\n\u003e Display images in the terminal\n\nWorks in any terminal that supports colors.\n\n\u003cimg src=\"screenshot.png\" width=\"1082\"\u003e\n\n*In iTerm, the image will be [displayed in full resolution](screenshot-iterm.jpg), since iTerm has [special image support](https://www.iterm2.com/documentation-images.html).*\n\n## Install\n\n```sh\nnpm install terminal-image\n```\n\n## Usage\n\n```js\nimport terminalImage from 'terminal-image';\n\nconsole.log(await terminalImage.file('unicorn.jpg'));\n```\n\nOptionally, you can specify the `height` and/or `width` to scale the image. That can be either the percentage of the terminal window or number of rows and/or columns. Please note that the image will always be scaled to fit the size of the terminal. If width and height are not defined, by default the image will take the width and height of the terminal.\n\nIt is recommended to use the percentage option.\n\n```js\nimport terminalImage from 'terminal-image';\n\nconsole.log(await terminalImage.file('unicorn.jpg', {width: '50%', height: '50%'}));\n```\n\nYou can set width and/or height as columns and/or rows of the terminal window as well.\n\n```js\nimport terminalImage from 'terminal-image';\n\nconsole.log(await terminalImage.file('unicorn.jpg', {width: 50}));\n```\n\nBy default, aspect ratio is always maintained. If you don't want to maintain aspect ratio, set `preserveAspectRatio` to false. However, your image will be scaled to fit the size of the terminal.\n\n```js\nimport terminalImage from 'terminal-image';\n\nconsole.log(await terminalImage.file('unicorn.jpg', {width: 70, height: 50, preserveAspectRatio: false}));\n```\n\n## API\n\nSupports PNG and JPEG images. Animated GIFs are also supported with `.gifBuffer` and `.gifFile`.\n\n### terminalImage.buffer(imageBuffer, options?)\n### terminalImage.file(filePath, options?)\n\nReturns a `Promise\u003cstring\u003e` with the ANSI escape codes to display the image.\n\n### terminalImage.gifBuffer(imageBuffer, options?)\n### terminalImage.gifFile(filePath, options?)\n\nReturns a function that can be called to stop the GIF animation.\n\n#### options\n\nType: `object`\n\n##### height\n\nType: `string | number`\n\nCustom image height.\n\nCan be set as percentage or number of rows of the terminal. It is recommended to use the percentage options.\n\n##### width\n\nType: `string | number`\n\nCustom image width.\n\nCan be set as percentage or number of columns of the terminal. It is recommended to use the percentage options.\n\n##### preserveAspectRatio\n\nType: `boolean`\\\nDefault: `true`\n\nWhether to maintain image aspect ratio or not.\n\n##### maximumFrameRate\n\n**Only works for `terminalImage.gifBuffer` or `terminalImage.gifFile`**\n\nType: `number`\\\nDefault: `30`\n\nMaximum framerate to render the GIF. This option is ignored when using iTerm.\n\n##### renderFrame\n\n**Only works for `terminalImage.gifBuffer` or `terminalImage.gifFile`**\n\nType: `(text: string) =\u003e void`\\\nDefault: [log-update](https://github.com/sindresorhus/log-update)\n\nCustom handler which is run for each frame of the GIF.\n\nThis can be set to change how each frame is shown.\n\n##### renderFrame.done\n\n**Only works for `terminalImage.gifBuffer` or `terminalImage.gifFile`**\n\nType: `() =\u003e void`\\\nDefault: [log-update](https://github.com/sindresorhus/log-update)\n\nCustom handler which is run when the animation playback is stopped.\n\nThis can be set to perform a cleanup when playback has finished.\n\n## Tip\n\n### Display a remote image\n\n```js\nimport terminalImage from 'terminal-image';\nimport got from 'got';\n\nconst body = await got('https://sindresorhus.com/unicorn').buffer();\nconsole.log(await terminalImage.buffer(body));\n```\n\n## Related\n\n- [terminal-image-cli](https://github.com/sindresorhus/terminal-image-cli) - CLI for this module\n- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal\n- [chalk](https://github.com/chalk/chalk) - Style and color text in the terminal\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fterminal-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsindresorhus%2Fterminal-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsindresorhus%2Fterminal-image/lists"}