Ink-asciify-image is a component for Ink.
npm install ink-asciify-image
import React from 'react'
import { render, Box } from 'ink'
import InkAsciifyImage from 'ink-asciify-image'
render(
<Box gap={1}>
<InkAsciifyImage
url="./avatar.jpg"
width={80}
height={40}
alt="Author's avatar"
/>
<InkAsciifyImage
url="./icon.png"
width={40}
height={40}
tryCorrectAspectRatio
renderInTwoBit
/>
<InkAsciifyImage
url="https://github.githubassets.com/images/modules/logos_page/GitHub-Mark.pnggg"
width={40}
height={20}
alt={
'The wrong path, accidentally typed two extra "g" at the end of the URL'
}
/>
</Box>,
)
const InkAsciifyImage: React.FC<{
url:⁰ string;
width:¹ number;
height:² number;
tryCorrectAspectRatio?:³ boolean;
renderInTwoBit?:⁴ boolean;
alt?:⁵ string;
}>;
- ⁰ [
url
]: URL of the rendered image, supports loading local URL, or network URL based on HTTP, supported image formats include "jpeg", "png" and "bmp". - ¹ [
width
]: Width of the rendered image. - ² [
height
]: Height of the rendered image. - ³ [
tryCorrectAspectRatio
]: Specifies whether to attempt to correct the aspect ratio of the rendered image, it often takes two ASCII characters to render a square like pixel point, this option would not eliminate the destructive effect on the original image's aspect ratio caused by the givenwidth
andheight
. - ⁴ [
renderInTwoBit
]: Specifies whether to render the image in monochrome. - ⁵ [
alt
]: Description of the image content, which will be displayed instead of an error message if the image fails to load.
/**
* @throws {RangeError} Value of `width` or `height` must be natural number.
*/
function asciifyImage(url:⁰ string, { width, height, tryCorrectAspectRatio, renderInTwoBit }: {
width:¹ number;
height:² number;
tryCorrectAspectRatio?:³ boolean;
renderInTwoBit?:⁴ boolean;
}):⁵ Promise<Array<string>>;
- ⁰ [
url
]: URL of the rendered image, supports loading local URL, or network URL based on HTTP, supported image formats include "jpeg", "png" and "bmp". - ¹ [
width
]: Width of the rendered image. - ² [
height
]: Height of the rendered image. - ³ [
tryCorrectAspectRatio
]: Specifies whether to attempt to correct the aspect ratio of the rendered image, it often takes two ASCII characters to render a square like pixel point, this option would not eliminate the destructive effect on the original image's aspect ratio caused by the givenwidth
andheight
. - ⁴ [
renderInTwoBit
]: Specifies whether to render the image in monochrome. - ⁵ [
asciifyImage()
]: It would return a promise instance contains an array which stores each line of ASCII characters rendered from image.
In order to prevent developers from encountering various problems that have to be solved when using this package, if they prefer ES modules, and let the image in the component can be rendered synchronously. By prepackaging core function, although possible errors are reduced, the total size of the package is
Ink-asciify-image is MIT licensed.