Socket
Socket
Sign inDemoInstall

ng2-image-viewer

Package Overview
Dependencies
6
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ng2-image-viewer

<section> This component uses the Image Viewer JS in it's core. Ng2-Image Viewer uses MIT license, so you can use it as you wish, feel free to help contributing with the code. Th


Version published
Weekly downloads
1.2K
decreased by-10.26%
Maintainers
1
Install size
90.6 kB
Created
Weekly downloads
 

Readme

Source

Welcome to Ng2-Image Viewer

This component uses the Image Viewer JS in it's core.

Ng2-Image Viewer uses MIT license, so you can use it as you wish, feel free to help contributing with the code.

This component allows you to:

  • Show images and PDF files, you can navigate through it;
  • You can load URL images, Base64 images and pdf;
  • Rotate each image as you wish;
  • Download images and PDF files (no additional configuration required);
  • Zoom in and out;
  • Fullscreen your files;
  • Fully responsive design

Upgrading from prior to 3.0

Take a look at this quick tutorial!

Donate:

You can donate on my Patreon!

My Patreon o/

Demo:

https://brenoprata10.github.io/ng2-image-viewer/

Requirements:

  • Material Icons;

How to use it:

The component already have some input references:

NameTypeRequiredDefault ValueDescription
idContainerstringXNULLIt is the id of the component on the HTML, this parameter allows you to inject as many components as you wish.
imagesBASE64/URL[]NULLIt is the array containing the base64 data, the component differs the images and the PDF files, so don't worry.
defaultDownloadNamestring'Image'It is the default name used on the file to be downloaded, Ex: Image 1, Image 2
rotatebooleantrueIt is the boolean that renders the rotate left and right buttons
resetZoombooleantrueIt is the boolean that renders the resetZoom button
zoomInButtonbooleantrueIt is the boolean that renders the Zoom In Button
zoomOutButtonbooleantrueIt is the boolean that renders the Zoom Out Button
zoomInTooltipLabelstringZoom InIt is the tooltip value you want for the zoom in button
zoomOutTooltipLabelstringZoom OutIt is the tooltip value you want for the zoom out button
downloadbooleantrueIt is the boolean that renders the download button
fullscreenbooleantrueIt is the boolean that renders the fullscreen button
showOptionsbooleantrueIt is the boolean that renders the options panel at the top right corner
showPDFOnlyOptionbooleantrueIt is the boolean that renders the PDF only button
loadOnInitbooleanfalseIt is the boolean that lets you choose if you want to load the component on the OnInit event or on the OnChanges event, It was created because i faced some trouble with the primeNG tab using the change event.
primaryColorstring'#0176bd'It is the background-color used on the footer and on the options panel
buttonsColorstring'white'It is the color used on the buttons on the options panel
buttonsHoverstring'#333333'It is the color used on the hover event, when the button receive the mouse pointer
enableTooltipbooleantrueIt is the boolean that renders the tooltips above the buttons
rotateRightTooltipLabelstring'Rotate right'It is the tooltip value you want for the rotate right button
rotateLeftTooltipLabelstring'Rotate left'It is the tooltip value you want for the rotate left button
resetZoomTooltipLabelstring'Reset zoom'It is the tooltip value you want for the reset zoom button
fullscreenTooltipLabelstring'Fullscreen'It is the tooltip value you want for the fullscreen button
downloadTooltipLabelstring'Download'It is the tooltip value you want for the download button
showPDFOnlyLabelstring'Show only PDF'It is the tooltip value you want for the show PDF only button
openInNewTabTooltipLabelstring'Open in new tab'It is the tooltip value you want for the open in new tab button
onNextEventEmitterIt is the event triggered when you change to next file, it emits the actual index of the array on the component
onPreviousEventEmitterIt is the event triggered when you change to previous file, it emits the actual index of the array on the component

Installation

To install this library, run:

$ npm install iv-viewer --save
$ npm install ng2-image-viewer --save

Consuming the library

And then from your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

// Import your library
import { ImageViewerModule } from 'ng2-image-viewer';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Specify your library as an import
    ImageViewerModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Now just add the these codes on your angular-cli.json file:

"styles": [
    "../node_modules/ng2-image-viewer/imageviewer.scss"
],

Once your library is imported, you can use its components, directives and pipes in your Angular application:

<!-- You can now use your library component in app.component.html -->
<h1>
  Image Viewer
</h1>
<app-image-viewer [images]="['iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==', 'https://picsum.photos/900/500/?random']"
[idContainer]="'idOnHTML'"
[loadOnInit]="true"></app-image-viewer>

Changelog

- Next versions spoilers:
  • Some design changes
  • Smart preview on container
  • Better button adjustment on mobile devices
- 3.0:
  • No longer uses Jquery!
  • Uses iv-viewer as peerDependency
  • Now the viewer uses the version 2.0 from Image Viewer JS, which is faster and fixes some bugs!
- 2.0:
  • Better performance
  • Smarter scaling when image overflows the container when rotated
  • Added support to URL images
  • Added Zoom in and Zoom out buttons
  • Added support to open url images in new tabs
  • Added tooltip label for url images in new tabs
- 1.0.9:
  • Increased performance
  • Fix bug when rotating images
  • Added tooltips
  • Added input to hide tooltips
  • Added input to costumize tooltips labels
  • Added new button: Show PDF only
  • Added new input to hide showPDFOnly button
  • Some design changes
- 1.0.8:
  • Added two event emitters(OnNext and OnPrevious)
  • Adjust on the smart scale when rotating

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © brenoprata10

Keywords

FAQs

Last updated on 02 Oct 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc