How to generate tiff thumbnail for dropzone

1.4k views Asked by At

Dropzone provides the following instructions for generating a custom thumbnail image:

myDropzone.on("addedfile", function(file) {
   if (!file.type.match(/image.*/)) {
      // This is not an image, so Dropzone doesn't create a thumbnail.
      // Set a default thumbnail:
      myDropzone.emit("thumbnail", file, "http://path/to/image");

      // You could of course generate another image yourself here,
      // and set it as a data url.

I can now read the binary image data into a my tif_canvas object using:

      var reader = new FileReader();   
      reader.onload = function (event) {
         var buffer = event.target.result;
         var tiff = new Tiff({ buffer: buffer });
         var tif_canvas = tiff.toCanvas();
         var width = tiff.width();
         var height = tiff.height();
         console.log(width + "x" + height);
      };

      reader.onerror = function (event) {
          console.error("File could not be read! Code " + event.target.error.code);
      };

      reader.readAsArrayBuffer(file);

   }
});

How do I set tif_canvas to the dropzone thumbnail URL in .emit("thumbnail", file, URL) how can I do this?

0

There are 0 answers