Created
          April 14, 2017 19:48 
        
      - 
      
- 
        Save psbolden/06ef7aff1afe4cd0465fa598c6873cd8 to your computer and use it in GitHub Desktop. 
    canvas to blob
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | //libraries used: | |
| https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js | |
| //Polyfills | |
| https://rawgit.com/eligrey/Blob.js/master/Blob.js | |
| https://rawgit.com/eligrey/canvas-toBlob.js/master/canvas-toBlob.js | |
| https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2014-11-29/FileSaver.min.js | |
| //all in one save option | |
| $( "#save" ).click(function() { | |
| var img = new Image, | |
| canvas = document.createElement('canvas'), | |
| ctx = canvas.getContext("2d"); | |
| img.crossOrigin = "Anonymous"; | |
| img.onload = function() { | |
| alert(img.src) | |
| canvas.height = this.height; | |
| alert(canvas.height); | |
| canvas.width = this.width; | |
| ctx.drawImage(img, 0, 0); | |
| quality = 1 // 0 - 1 | |
| canvas.toBlob(function(blob){ | |
| saveAs(blob, 'aa.jpg'); // or 'aa.png' | |
| }, 'image/jpeg', quality); // or 'image/png' | |
| }; | |
| img.src = "yourimageurlgoeshere"; | |
| }); | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment