# dyna-image

> Render image in fit or fill mode. Render easily responsive images using the and srcSet DOM's features.

Latest version **4.0.3** (published 2026-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install dyna-image
pnpm add dyna-image
yarn add dyna-image
bun add dyna-image
```

## Health

**Score 65/100 (B)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 4.0.3 |
| Published | 2026-09-24 |
| First published | 2020-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=20.0.0 <25.0.0 |
| Dependencies | 6 |
| Unpacked size | 266.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Anel dev |
| Maintainers | dennisat |
| Keywords | react, component, image |

## Links

- npm: https://www.npmjs.com/package/dyna-image
- Repository: https://github.com/aneldev/dyna-image
- Homepage: https://github.com/aneldev/dyna-image#readme
- Issues: https://github.com/aneldev/dyna-image/issues
- npm.io page: https://npm.io/package/dyna-image

## Dependencies (6)

- [dyna-error](https://npm.io/package/dyna-error.md) ^4.0.13
- [object-hash](https://npm.io/package/object-hash.md) ^3.0.0
- [use-debounce](https://npm.io/package/use-debounce.md) ^9.0.3
- [@material-ui/core](https://npm.io/package/@material-ui/core.md) ^4.11.0
- [@material-ui/icons](https://npm.io/package/@material-ui/icons.md) ^4.9.1
- [react-resize-detector](https://npm.io/package/react-resize-detector.md) ^10.0.1

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 4.0.3 (latest) — 2026-09-24
- 4.0.2 — 2024-11-24
- 3.1.11 — 2024-05-03
- 3.1.10 — 2023-08-06
- 3.1.9 — 2023-08-06
- 3.1.7 — 2023-03-29
- 3.1.5 — 2023-03-14
- 3.1.4 — 2023-03-14
- 3.1.3 — 2023-03-14
- 3.1.2 — 2023-03-14
- 3.1.1 — 2023-03-14
- 3.0.2 — 2022-06-20
- 3.0.1 — 2022-06-10
- 2.2.2 — 2022-06-06
- 2.2.1 — 2022-06-06
- … 9 more at https://npm.io/package/dyna-image/versions

## README

# Dyna Image

Render image in Fit or Fill mode. Render responsive images.

# Demo

```
git clone http://github.com/aneldev/dyna-image
cd dyna-image
yarn install
yarn start

```

# Package

This package comes with two components:

- `DynaImage` that renders an image in the given width & height space
- `DynaResponsiveImage` renders an image in the given width. The height is auto

The main difference is that the `DynaImage` uses the whole parent's available space, width, and height,
while the `DynaResponsiveImage` uses only the width, the height is auto.

Also, note that the `DynaImage` is not SEO friendly! Use it for decoration only.
The `DynaReposniveImage` is SEO friendly and supports multiple versions of an image for responsive representation.

## DynaImage

Render image in Fit or Fill mode.

Create a `<div>` width some `width` and `height` and inside the `<DynaImage>`. The `<DynaImage>` will occupy the full width and height of the parent `<div>`.
It will render the image in Fit or Fill mode.

The `<div>`'s `width` and `height` would also be obtained by `flex boxes` or `grid system`.

### Modes

The `EImageMode` would be:

#### FIT

In Fit mode, the image will fit in the parent div, which means that we will have horizontal or vertical empty spaces.

#### FILL

In Fill mode, the image will cover the whole area of the parent div, which means that the image will be cropped vertically or horizontally.

### Examples

```
import {DynaImage, EImageMode} from "dyna-image";
...

<div style={{ height: '400px', backgroundColor: 'black' }}>
  <DynaImage src="https://www.example.com/eifel.jpg"/>
</div>
```
or
```
<div style={{ height: '400px' }}>
  <DynaImage 
    src="https://www.example.com/eifel.jpg"
    mode={EImageMode.FILL}
  />
</div>
```


### Props

Render image in Fit or Fill mode.

```
IDynaImageProps {
  className?: string;
  style?: React.CSSProperties;      // Container's style
  imgStyle?: React.CSSProperties;   // Image style (is div with background image)

  src: string;

  mode?: EImageMode;                // Default: EImageMode.FIT
  alt?: string;
  content?: JSX.Element;

  showLoadingSpinner?: boolean;     // Default is false
  showBrokenImageOnFail?: boolean;  // Default is true

  crop?: {
    percentageX1: number;           // 0..100 position
    percentageY1: number;           // 0..100 position
    percentageX2: number;           // 0..100 position
    percentageY2: number;           // 0..100 position
  };
  horizontalMirror?: boolean;
  verticalMirror?: boolean;
  blackAndWhite?: boolean;

  onLoad?: () => void;
  onError?: (error: any) => void;
}
```

#### `content` property

Allows rendering above the image. The container has the entire width and height of the image.

#### `showLoadingSpinner` property

On loading, it shows the Material UI CircularProgress animated icon.

#### `showBrokenImageOnFail` property

On failed load, it shows the Material UI BrokenImage icon.

## DynaResponsiveImage

### Props

```
IDynaResponsiveImageProps {
  className?: string;
  imgStyle?: React.CSSProperties;   // Image style (is div with background image)

  srcSet: {
    main: string;         // Use it as default image
    W192?: string;
    W384?: string;
    W768?: string;
    W1024?: string;
    W2048?: string;
    W4096?: string;
  };

  alt?: string;
  content?: JSX.Element;

  horizontalMirror?: boolean;
  verticalMirror?: boolean;

  blackAndWhite?: boolean;

  zoom?: {
    percentageX: number;  // Default is 50%. Examples: 0& 20% 100%
    percentageY: number;  // Default is 50%. Examples: 0& 20% 100%
    zoom: number;         // Default is 1. 1 1.2 1.5
  };

  onLoad?: () => void;
  onError?: (error: any) => void;
}
```

### `srcSet` property

Main is required, but all other resolutions are optional.

### `content` property

Allows rendering above the image. The container has the full width and height.

### `content` property

Allows zooming into the image on a specific point on the picture by percentage x/y.
This has a crop effect.

# Change log

## 1.2.3

- First version.
- Works with React 16

## 2.0.0

- Works with React 17

## 3.0.0

- Change: `<DynaImage>`'s `ACTUAL` mode is omitted.
- New: `<DynaResponseveImage>` SEO friendly and supports multiple responsive image versions.

## 4.0.0

- Switch to React V18

---
_Source: https://npm.io/package/dyna-image · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
