# ionic-img-viewer

> Ionic 2 component providing a Twitter inspired experience to visualize pictures.

Latest version **2.9.0** (published 2017-11-11) · MIT license · 448 weekly downloads

## Install

```sh
npm install ionic-img-viewer
pnpm add ionic-img-viewer
yarn add ionic-img-viewer
bun add ionic-img-viewer
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.9.0 |
| Published | 2017-11-11 |
| First published | 2016-08-09 |
| Weekly downloads | 448 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 279 |
| Author | Orion Charlier |
| Maintainers | riron |
| Keywords | ionic2, image, angular2, component |

## Links

- npm: https://www.npmjs.com/package/ionic-img-viewer
- Repository: https://github.com/Riron/ionic-img-viewer
- Homepage: https://github.com/Riron/ionic-img-viewer#readme
- Issues: https://github.com/Riron/ionic-img-viewer/issues
- npm.io page: https://npm.io/package/ionic-img-viewer

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 2.9.0 (latest) — 2017-11-11
- 2.8.0 — 2017-11-11
- 2.7.3 — 2017-10-13
- 2.7.2 — 2017-10-10
- 2.7.0 — 2017-10-03
- 2.6.1 — 2017-08-06
- 2.6.0 — 2017-08-06
- 2.5.0 — 2017-08-05
- 2.4.0 — 2017-06-20
- 2.3.0 — 2017-06-08
- 2.2.0 — 2017-06-08
- 2.1.0 — 2017-05-03
- 2.0.0 — 2017-05-02
- 1.3.4 — 2017-05-02
- 1.3.3 — 2017-04-06
- … 17 more at https://npm.io/package/ionic-img-viewer/versions

## README

# Image viewer for Ionic 2+

[![NPM](https://nodei.co/npm/ionic-img-viewer.png?downloads=true)](https://nodei.co/npm/ionic-img-viewer/)

Ionic 2 plugin providing a Twitter inspired experience to visualize pictures.

![Plugin preview](https://raw.githubusercontent.com/riron/ionic-img-viewer/master/demo/img-viewer2.gif)

## Features

- Tap on the pic to see it fullscreen
- Slide up/down to close the view
- Tap on the navigation arrow to close the view
- Double tap / pinch the pic when open to zoom

## Demo

[Demo on Plunkr](http://embed.plnkr.co/isbTOupNw51JjaaksbSE/)

## Installation

Make sure you have Ionic and Angular installed.

```
npm install --save ionic-img-viewer
```

**Check you peer-dependencies warnings after `npm install` to make sure you are using a version in accordance to your Ionic version.**

### For Ionic 2 RC.0 and later:

```typescript
import { IonicImageViewerModule } from 'ionic-img-viewer';

@NgModule({
  imports: [
    IonicImageViewerModule
  ]
})
export class AppModule {}
```

## Usage


### As a directive

Add the `imageViewer` property to the image element.

```html
<img src="IMAGE_URL" imageViewer />
```

If you use thumbnails and want to display bigger images, you can use it like so :

```html
<img src="IMAGE_URL" imageViewer="OTHER_IMAGE_URL" />
```

However, if `OTHER_IMAGE_URL` is not preloaded, the animation might suffer. There will be no loaded image to display in order to have the nice and smooth transition, and you might see the image blinking while opening it.

So try to cache your image before the call if you use it that way.

### React to close event

If you need to, you can attach a callback to `close` event, fired right after the image viewer element has been closed :

```html
<img src="IMAGE_URL" imageViewer (close)="callbackAfterImageViewerCloses()" />
```

### Programmatic usage

If you don't want to use the directive, you can create an instance of the ImageViewer yourself and trigger the presentation whenever you want.

```html
<img src="IMAGE_URL" #myImage (click)="presentImage(myImage)" />
```

```typescript
import { ImageViewerController } from 'ionic-img-viewer';

export class MyPage {
  _imageViewerCtrl: ImageViewerController;

  constructor(imageViewerCtrl: ImageViewerController) {
    this._imageViewerCtrl = imageViewerCtrl;
  }

  presentImage(myImage) {
    const imageViewer = this._imageViewerCtrl.create(myImage);
    imageViewer.present();

    setTimeout(() => imageViewer.dismiss(), 1000);
    imageViewer.onDidDismiss(() => alert('Viewer dismissed'));
  }
}
```

As a second argument to the `create(imageElement, config)` method, you can pass an object with the following options.

| Options               | Type     | Description  |
| ---------------       |:---------| :------------|
| fullResImage          | string   | A full resolution image to display instead of the original image when open. Defaults to null |
| onCloseCallback       | Function | Function to be called when the ImageViewer quits. Defaults to null |
| enableBackdropDismiss | boolean  | Boolean to enable dismiss when clicking on the back drop. Defaults to false |

# Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md).

Thank you, [contributors]!

[contributors]: https://github.com/Riron/ionic-img-viewer/graphs/contributors

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