Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make images zoomable with Ionic 2

I've got a page with one single image, how can I make this image zoomable?

My Page

like image 597
matthiasunt Avatar asked Apr 13 '16 06:04

matthiasunt


People also ask

What is a zoomable image?

<div id="myresult" class="img-zoom-result"></div>

Where do you put images in ionic?

add the image to app directory scr/assets/img/Test. jpg.

How do I create a zoomable view in Ionic 4?

With Ionic 4 the old ion-scroll is gone and with it the way we created a zoomable view. The good news is the Slides are still there and we can use them to create great effects and zooming inside our Ionic 4 app! In the past we have used packages that allowed us to zoom in or a general package to create an image gallery.

Why we will create our own ionic image gallery?

If you have specific requirements, there might not be an out of the box solution that works fine for you, that’s why we will create our own Ionic image gallery. We will display images in a gallery like infinite loop where we can always see the end of the previous image and the start of the following.

Is it possible to zoom in on a photo gallery?

Additional, if you want image zooming inside your standard gallery view, your head might explode without the proper knowledge. Let me present you an easy way how to show an image gallery like in the Facebook app, with additional image zooming functionality for every picture while staying inside your carousel!

Is the old Ion scroll still available in Ionic 4?

With Ionic 4 the old ion-scroll is gone and with it the way we created a zoomable view. The good news is the Slides are still there and we can use them to create great effects and zooming inside our Ionic 4 app!


1 Answers

You can use Image viewer for Ionic 2+

  • Installation

npm install --save ionic-img-viewer

  • Add in app.module.ts
import { IonicImageViewerModule } from 'ionic-img-viewer';

@NgModule({
  declarations: [
    MyApp, 
    HomePage
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    IonicImageViewerModule
  ],
  • Programmatic usage :

< img src="IMAGE_URL" #myImage (click)="presentImage(myImage)" />

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(); 
  }
}

DEMO : Demo ionic-img-viewer

like image 90
Yassine Abid Avatar answered Oct 12 '22 07:10

Yassine Abid