Skip to main content
Embed images with sizing, aspect ratio, and cropping.

Props


Loading images

Local files

Remote URLs

Bytes and data URIs

Object storage and custom sources

Pass loadFile to render or renderToBuffer to fetch src strings yourself, for example keys in a private bucket. The same function loads the base document and fonts:
Each distinct source is loaded once, even if it appears many times.

Supported formats

  • PNG
  • JPEG
  • GIF (static)
  • BMP
The format is detected from the file contents, not the extension. If an image cannot be loaded or is in another format, render() rejects with an error naming the src. Photos from phones and cameras often store their rotation in EXIF metadata, which Word ignores. React DOCX applies it, so photos appear upright.

Compression

Like Word’s Compress Pictures, images are downsampled to a resolution for the size they are displayed at, then re-encoded. A 12-megapixel photo shown 3 inches wide becomes 660 pixels wide at the default setting, a fraction of the original size. Images are never enlarged. Set it for a whole document, a part of it, or one image. The closest setting wins:
"original" keeps the bytes as they are, except for photos with an EXIF rotation, which are re-encoded upright at high quality. GIFs are always kept as they are. An image used at several sizes is stored once, at the resolution its largest use needs. Compression uses the sharp package, installed with React DOCX.

Sizing

Units

Width only

Height calculated from original aspect ratio:

Height only

Width calculated from original aspect ratio:

Both

Explicit dimensions (may stretch):

No dimensions

Uses the image’s size at 96 pixels per inch, scaled down to fit between the page margins if it is larger, as Word does when inserting a picture:

Aspect ratio

Control aspect ratio with Tailwind classes:

Object fit

Control how image fills the space:

Cover (crop to fill)

Crops image to fill dimensions. Maintains aspect ratio, removes overflow.

Contain (fit inside)

Scales to fit within dimensions. May have empty space.

Default (stretch)

Stretches to fill. May distort image.

Common patterns

Logo in header

Product image

Thumbnail grid (in table)

Screenshot with border


Floating

By default an image sits in the line like a character. float places it at the left or right edge of the column, with the text wrapping around it:

Limitations

  • Floating images align to the left or right edge of the column; free positioning is not supported
  • No rotation or transforms (other than applying EXIF orientation)
  • No filters or effects
  • No SVG support
  • No animated GIFs (static frame only)