Angular component for zoomable images – NgxImageZoom

An image zoom component for Angular 2+ that works with both URLs to images and inline images. NgxImageZoom is inspired by angular2-image-zoom and JQuery libraries such as jQuery Zoom and elevateZoom-plus but a pure Angular2+ implementation of similar concepts. This plugin works with both URLs to images and in-line images (Data URI).
angular-image-zoom-component

Installation

installing using NPM

$ npm install ngx-image-zoom --save


From your Angular AppModule:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
 
import { AppComponent } from './app.component';
 

import { NgxImageZoomModule } from 'ngx-image-zoom';
 
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    NgxImageZoomModule.forRoot() // <-- Add this line
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Once the library is imported, you can use its component in your Angular application:

<!-- You can now use NgxImageZoom component in app.component.html -->
<h1>
  {{title}}
</h1>
<ngx-image-zoom
    [thumbImage]=myThumbnail
    [fullImage]=myFullresImage
></ngx-image-zoom>


Zoom ratio
The zoom ratio used in the minZoomRatio and maxZoomRatio settings refer to the relative size of the thumbnail and the full size image. The baseRatio default value is the calculated ratio that would make the zoomed image equal in size to the thumbnail. For example, if the full size image is 10x larger than the thumbnail, then minZoomRatio will default to 0.1, as in the full size image can at its smallest be shown at 0.1 times its original size. The default value for maxZoomRatio being 1 means the largest the fullSize image can appear is twice its original size.

Available options
All settings except thumbImage are optional. If no fullImage is provided the thumbImage will be used as the high resolution version as well.

Option Default value Description
thumbImage none (Required) The smaller version of the image that will be shown when there’s no interaction by the user.
fullImage none The full resolution version of the image to be used when zooming. If not supplied thumbImage will be used.
magnification 1 The zoom factor to be used by default. 1 means we use the fullImage at its actual resolution.
zoomMode ‘hover’ The mode of zooming to use, these are explained in a table below.
enableScrollZoom false Boolean that toggles if the mouse wheel should be captured when hovering over the image to adjust magnification.
scrollStepSize 0.1 When using scroll zoom this setting determines how big steps each scroll changes the zoom.
enableLens false If enabled only a small portion around the mouse cursor will actually magnify instead of the entire image area.
lensWidth 100 Width of the lens, if enabled.
lensHeight 100 Height of the lens, if enabled.
circularLens false Make the lens circular instead of square. This will only look good if width and height are equal.
minZoomRatio baseRatio Lower limit on how much zoom can be applied with scrollZoom enabled. See below for details.
maxZoomRatio 2 Upper limit on how much zoom can be applied with scrollZoom enabled. See below for details.
scrollParentSelector none Selector of parent scrolling view as string. This avoid zoom gap with cursor when the scrolling view is not the main window. Example : ‘#scrolling-frame’

See live demo and download source code.

DEMO | DOWNLOAD

This awesome plugin is developed by wittlock. Visit their official github repository for more information and follow for future updates.