Old images keeps replacing the new one in canvas with CamanJS when I apply filters

301 Views Asked by At

This is part of my code that uploads the image file. I have only shown the portion where I update the image variable as well as the CamanJS instance:

updateImage() {
  img = new Image();
  img.src = reader.result;
  img.onload = function () {
      Caman('#canvas', img, function () {
           this.reloadCanvasData();
      });
  }      
}, false);

This is the code where I apply the filters:

$("button").on('click', function (e) {
    Caman('#canvas', img, function () {
        this.revert(false);
    });

    Caman('#canvas', img, function () {
        Apply the filters here.
        this.render();
    });
});

If I load an image and apply a filter, it works. If I load another image, it shows up in the canvas but applying filters after that changes my canvas to the first image. Is there anything that I can do to update the CamanJS data?

0

There are 0 best solutions below