6

So I have a webpage with two image elements. It is basically a website where you upload an image and it encrypts a secret massage with steganography. I want to show the difference that is not otherwise visible and I found Resemble.js which is a library to compare images. It gets two files as arguments and I would like to use my image sources instead of files since I don't want to save the images generated.

To sum up, I want to get rid of the requests and get my images via sources in the HTML but I don't know how to get it to work with Resemble.js since it accepts only files.

How the second image is generated:

cover.src = steg.encode(textarea.value, img, { 
  "width": img.width, 
  "height": img.height
});

The JavaScript working with files:

(function () {
  var xhr = new XMLHttpRequest();
  var xhr2 = new XMLHttpRequest();
  var done = $.Deferred();
  var dtwo = $.Deferred();

  try {
    xhr.open('GET', 'static/original.png', true);
    xhr.responseType = 'blob';
    xhr.onload = function (e) { done.resolve(this.response); };
    xhr.send();

    xhr2.open('GET', 'static/encoded.png', true);
    xhr2.responseType = 'blob';
    xhr2.onload = function (e) { dtwo.resolve(this.response); };
    xhr2.send();
  } catch (err) {
    alert(err);
  }

  $('#example-images').click(function () {
    $.when(done, dtwo).done(function (file, file1) {
      if (typeof FileReader === 'undefined') {
        resembleControl = resemble('./static/original.png')
          .compareTo('./static/encoded.png')
          .onComplete(onComplete);
      } else {
        resembleControl = resemble(file)
          .compareTo(file1)
          .onComplete(onComplete);
      }
    });

    return false;
  });

}());
n1stre
  • 5,856
  • 4
  • 20
  • 41
TenebrisNocte
  • 179
  • 10
  • What are your image sources? Aren't they files? – mhatch Aug 28 '17 at 19:27
  • Your script is using the FileReader. It's not possible to load server files into this: _File objects may be obtained from a FileList object returned as a result of a user selecting files using the input element, from a drag and drop operation's DataTransfer object, or from the mozGetAsFile() API on an HTMLCanvasElement._ Possible duplicate of: https://stackoverflow.com/questions/39662388/javascript-filereader-onload-get-file-from-server – icecub Aug 28 '17 at 19:28
  • I don't suppose you use any server language, do you? – Tiramonium Oct 13 '17 at 11:32

0 Answers0