Giter Site home page Giter Site logo

yeshanjay / ngx-imageviewer Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hallysonh/ngx-imageviewer

0.0 1.0 0.0 18.12 MB

Angular 5 Image Viewer Component based on Canvas

License: MIT License

JavaScript 4.92% TypeScript 79.93% HTML 10.08% CSS 5.07%

ngx-imageviewer's Introduction

Angular 6 - Canvas Image/PDF Viewer

travis build Greenkeeper badge version MIT License semantic-release

This project generate a image/pdf viewer using canvas.

Features

  • Configurable
  • Resizeble component
  • Supports JPEG, PNG, GIF and PDF
  • Support File Objects
  • Avaliable actions:
    • Rotate
    • Zoom
    • Reset to maximize size
    • Free movable
    • Change page (available just for PDF files)

Demo

Access a demo here or download this project and execute: yarn && yarn start or npm install && npm run start to self server it.

Install

Run yarn add @hallysonh/ngx-imageviewer hammerjs to install it and its dependency.

hammerjs is currently mandatory, but it will be optional in a future release.

Icon Font

You can use any icon font to render the button's icons. However, the default icon font is the Google's Material Icons. To use them you can just add the follow line to your index.html:

<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons">

Optionaly, you can also install the font library via npm or yarn.

when using another icon font, you should provide a config object with the button icon mapping

Basic Usage

After import the module ImageViewerModule:

import { ImageViewerModule } from '@hallysonh/ngx-imageviewer';

@NgModule({
  imports: [
    ImageViewerModule
  ]
})
export class AppModule { }

Use the follow code on your html:

<ngx-imageviewer [src]="imageSrc"></ngx-imageviewer>

Optionaly, you can provide the fields width and height. If you omit those values, the width and height in the config object will be used.

Add PDF Support

To add PDF rendering support, you must first include pdfjs by running yarn add [email protected] and add its reference in your angular.json file, like below:

{
  ...
  "scripts": [
    {
      "input": "node_modules/pdfjs-dist/build/pdf.min.js"
    }, {
      "input": "node_modules/pdfjs-dist/build/pdf.worker.min.js"
    }
  ],
  ...
}

Custom Configuration

Optionaly, you can provide a custom configuration like below:

import { IMAGEVIEWER_CONFIG, ImageViewerConfig } from '@hallysonh/ngx-imageviewer';
...
const MY_IMAGEVIEWER_CONFIG: ImageViewerConfig = {
  buttonStyle: {
    bgStyle: '#B71C1C' // custom container's background style
  }
};
...
@Component({
  ...
  providers: [
    {
      provide: IMAGEVIEWER_CONFIG,
      useValue: MY_IMAGEVIEWER_CONFIG
    }
  ]
  ...
})
...

The default configuration available is:

export const IMAGEVIEWER_CONFIG_DEFAULT: ImageViewerConfig = {
  width: 800, // component default width
  height: 600, // component default height
  bgStyle: '#ECEFF1', // component background style
  scaleStep: 0.1, // zoom scale step (using the zoom in/out buttons)
  rotateStepper: false, // touch rotate should rotate only 90 to 90 degrees
  loadingMessage: 'Loading...',
  buttonStyle: {
    iconFontFamily: 'Material Icons', // font used to render the button icons
    alpha: 0.5, // buttons' transparence value
    hoverAlpha: 0.7, // buttons' transparence value when mouse is over
    bgStyle: '#000000', //  buttons' background style
    iconStyle: '#ffffff', // buttons' icon colors
    borderStyle: '#000000', // buttons' border style
    borderWidth: 0 // buttons' border width (0 == disabled)
  },
  tooltips: {
    enabled: true, // enable or disable tooltips for buttons
    bgStyle: '#000000', // tooltip background style
    bgAlpha: 0.5, // tooltip background transparence
    textStyle: '#ffffff', // tooltip's text style
    textAlpha: 0.9, // tooltip's text transparence
    padding: 15, // tooltip padding
    radius: 20 // tooltip border radius
  },
  zoomOutButton: { // zoomOut button config
    icon: 'zoom_out', // icon text
    tooltip: 'Zoom out', // button tooltip
    sortId: 0, // number used to determine the order of the buttons
    show: true // used to show/hide the button
  },

  // shorter button configuration style
  nextPageButton: createButtonConfig('navigate_next', 'Next page', 0),
  beforePageButton: createButtonConfig('navigate_before', 'Previous page', 1),
  zoomInButton: createButtonConfig('zoom_in', 'Zoom in', 1),
  rotateLeftButton: createButtonConfig('rotate_left', 'Rotate left', 2),
  rotateRightButton: createButtonConfig('rotate_right', 'Rotate right', 3),
  resetButton: createButtonConfig('autorenew', 'Reset', 4)
};

ngx-imageviewer's People

Contributors

hallysonh avatar greenkeeper[bot] avatar angular-cli avatar gravatasufoca avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.