Skip to content

Image

The Image component displays images in terminal apps using ANSI block rendering. It supports file or buffer sources, resizing, and error handling.

Basic Usage

vue
<template>
  <Image src="/path/to/image.png" />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Props

NameTypeDefaultDescription
srcstring | objectrequiredSource of the image (file path or buffer)
widthnumber | stringnullWidth of the image in columns or percentage
heightnumber | stringnullHeight of the image in rows
preserveAspectRatiobooleantruePreserve the aspect ratio when resizing
altstring''Alternative text for the image
errorColorstring'red'Color for error messages
errorBorderStylestring'rounded'Border style for error display

Layout Props (Box Props)

NameTypeDefaultDescription
flexnumber | stringnullFlex shorthand when inside a flex container
flexGrownumbernullFlex grow factor
flexShrinknumbernullFlex shrink factor
flexBasisnumber | stringnullFlex basis
alignSelfstringnullSelf alignment: 'auto', 'flex-start', 'flex-end', 'center', 'stretch', 'baseline'
widthnumber | stringnullWidth (chars or %)
heightnumber | stringnullHeight (rows)
minWidthnumbernullMinimum width
maxWidthnumbernullMaximum width
minHeightnumbernullMinimum height
maxHeightnumbernullMaximum height
paddingnumbernullPadding
paddingLeftnumbernullLeft padding
paddingRightnumbernullRight padding
paddingTopnumbernullTop padding
paddingBottomnumbernullBottom padding
marginnumbernullMargin
marginLeftnumbernullLeft margin
marginRightnumbernullRight margin
marginTopnumbernullTop margin
marginBottomnumbernullBottom margin

Customization

Fixed Width

vue
<template>
  <Image src="/path/to/image.png" :width="40" />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Percentage Width

vue
<template>
  <Image src="/path/to/image.png" width="50%" />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Fixed Height

vue
<template>
  <Image src="/path/to/image.png" :height="10" />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Disable Aspect Ratio Preservation

vue
<template>
  <Image src="/path/to/image.png" :preserveAspectRatio="false" />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Error Handling

Custom Error Message

vue
<template>
  <Image
    src="/path/to/image.png"
    errorColor="yellow"
    errorBorderStyle="double"
  />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Alternative Text

vue
<template>
  <Image
    src="/path/to/image.png"
    alt="Description of the image"
  />
</template>

<script setup>
import { Image } from 'vuetty';
</script>

Usage with Other Components

With Box

vue
<template>
  <Box :padding="1" border>
    <Image src="/path/to/image.png" />
  </Box>
</template>

<script setup>
import { Image, Box } from 'vuetty';
</script>

With Row and Col

vue
<template>
  <Row gap="2">
    <Col flex="1">
      <Image src="/path/to/image1.png" />
    </Col>
    <Col flex="1">
      <Image src="/path/to/image2.png" />
    </Col>
  </Row>
</template>

<script setup>
import { Image, Row, Col } from 'vuetty';
</script>

Advanced Usage

Loading Images from Buffers

vue
<template>
  <Image :src="imageBuffer" />
</template>

<script setup>
import { ref } from 'vue';
import { Image } from 'vuetty';

const imageBuffer = ref(Buffer.from(...));
</script>

Dynamic Image Source

vue
<template>
  <Image :src="dynamicImagePath" />
</template>

<script setup>
import { ref } from 'vue';
import { Image } from 'vuetty';

const dynamicImagePath = ref('/path/to/image.png');
</script>

Released under the MIT License.