1

I'm trying to create some tool that saves text to images, now i've built something that works with a preview. But i've got one problem with the download, it keeps downloading a corrupt image...

I have tried a lot of things but nothing seems to work, my code for the download so far is:

  download = document.getElementById('img-download');
  download.addEventListener('click', prepareDownload, false);

  function prepareDownload() {
     var data = canvas.toDataURL();
     download.href = data;
  }

It is giving me 0 errors..

I have added a jsFiddle for better understanding: http://jsfiddle.net/4nehA/

EDIT: Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

is giving me the hard time..

user2099810
  • 361
  • 5
  • 15

1 Answers1

1

Please note that your jsfiddle lacks some html elements, which causes errors in the main function resulting in the prepareDownload function not being fired at all.

Your problem might be caused by a bug mentioned here: Blank PNG / Tainted canvases may not be exported (not using images)

I'm not sure if it can be verified over jsfiddle, because when I'm testing your code on firefox, I'm having the following issue: Is it possible to avoid "The operation is insecure" when using Canvas?

Community
  • 1
  • 1
kihu
  • 842
  • 5
  • 13
  • Thanks for your answer, i'm looking into it now. As you said i was indeed missing one element. And now it gives me the error: Uncaught security error failed to excecute yadayadayada. But thanks now i've got something to go on :) – user2099810 Mar 31 '14 at 10:42