AngularJS file upload from ngThumb directive (with angular-file-upload) AngularJS file upload from ngThumb directive (with angular-file-upload) angularjs angularjs

AngularJS file upload from ngThumb directive (with angular-file-upload)


Since the uploader is working fine already and you're able to save the images into the database, all you need to do is to show the uploaded images as thumbnails on a canvas.

That can be done using some jQuery like this:

// source of a large image - replace this with the URL of the uploaded image (served from the database)var IMAGE_SRC = "http://cdn-media-1.lifehack.org/wp-content/files/2014/09/activities-on-the-beach.jpg";// set the height for the thumbnail - your uploader currently has 100var height = 100;function drawImage() {  // create a new Image object  var img = new Image();  // set up the onLoad handler on the image object to draw the thumbnail into the canvas  img.onload = function() {    // calculate the thumbnail width for the fixed height above, respecting the image aspect ratio    var width = this.width / this.height * height;    // set the dimensions on the canvas    $("canvas").attr({      width: width,      height: height    });    // draw the image from the loaded image object    $("canvas")[0].getContext("2d").drawImage(img, 0, 0, width, height);  };  // set the source of the image object to the URL of the uploaded image (served from the database)  img.src = IMAGE_SRC;}// Do all of this when the button is clicked$("button").click(drawImage);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><button>Load image into Canvas</button><br /><br /><canvas></canvas>