AngularJS thumbnail service to generate blob or base64 data as well as directive to display an image as thumbnail in canvas. Perfect for an Ionic app.
http://kennyki.github.io/angular-thumbnail
- Generate thumbnail for pictures from gallery/camera to store locally or remotely in PhoneGap/cordova apps. You don't need a plugin for that.
- Display thumbnail for pictures from gallery/local db in a list in PhoneGap/cordova apps. Because CSS resizing on many pictures can be very consuming.
- Resizing before upload to a server.
- Generating thumbnails from large images in a desktop web application.
- first of all, CSS resizing (setting widthandheight) should be sufficient as most of the desktop will have enough power to do it. But:
- consider requesting for smaller images from the server.
- if the images are external you should cache them in your own server and resize them there.
 
- first of all, CSS resizing (setting 
- Install through bower bower install angular-thumbnailor download the package manually.
- In your index.html, import:
- canvas-to-blob.min.js only if you need to generate blob data
- angular-thumbnail.min.js
 
- Add dependency to your module angular.module('', ['ui.thumbnail']);
- Enable CORS <access origin="*"/>in the config.xml
angular.module('', ['ui.thumbnail'])
.config(function(ThumbnailServiceProvider) {
  // otherwise both defaults to 100
  ThumbnailServiceProvider.defaults.width = 150;
  ThumbnailServiceProvider.defaults.height = 150;
})
;
Hmm.. it's clearer in the demo's source code.
A ThumbnailService dependency can be injected into a controller.
- 
Parameters: - src: either a url or base64 string
- opts: an optional object of- width: number (defaults to 100)
- height: number (defaults to 100)
- returnType: 'blob' (defaults to 'base64')
- type: 'image/jpeg' (defaults to 'image/png')
- encoderOptions: A number between 0 and 1 indicating image quality if the requested type is 'image/jpeg' or 'image/webp'.
 
 
- 
Returns: a promise that resolves with a base64 string or blob