JavaScript How can I get Blob data from image URL using javascript blob data from base64,dataurl to blob,blob data to

I have a solution but its taking too much time. Here is my solution.

//------------ Image url to base64 -------------//

    function convertImgToBase64(url, callback, outputFormat){
        var img = new Image();
        img.crossOrigin = 'Anonymous';
        img.onload = function(){
        var canvas = document.createElement('CANVAS'),
        ctx = canvas.getContext('2d'), dataURL;
        canvas.height = this.height;
        canvas.width = this.width;
        ctx.drawImage(this, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback(dataURL);
        canvas = null; 
     };
       img.src = url;
    }

   //------------ convert base64 into Blob -------------//
   function dataURItoBlobImg(dataURI) {
     var byteString;
     if (dataURI.split(',')[0].indexOf('base64') >= 0)
        byteString = atob(dataURI.split(',')[1]);
     else
        byteString = unescape(dataURI.split(',')[1]);
     var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
     var ia = new Uint8Array(byteString.length);
     for (var i = 0; i < byteString.length; i++) {
         ia[i] = byteString.charCodeAt(i);
     }
     return new Blob([ia], {type:mimeString});
    }

Now thing is first I have to convert image into base64 and after that I can convert into Blob, is there is any way I can directly convert into Blob from image URL.

Thanks.

Answer:1

I was trying to get the background color of an element using javascript: URL: https://mathemagiker.de/ Javascript: document.getElementById('angebot').style.backgroundColor Result: Nothing However ...

I was trying to get the background color of an element using javascript: URL: https://mathemagiker.de/ Javascript: document.getElementById('angebot').style.backgroundColor Result: Nothing However ...

How I can use selectize.js with remote source? I have followed this example: $('#select-repo').selectize({ valueField: 'url', labelField: 'name', searchField: 'name', create: false, ...

How I can use selectize.js with remote source? I have followed this example: $('#select-repo').selectize({ valueField: 'url', labelField: 'name', searchField: 'name', create: false, ...

  1. selectize remote data
  2. selectize remote source
  3. selectize remote data loading
  4. selectize remote
  5. selectize remote source example
  6. selectize remote data example
  7. selectize remote json

i'm trying to inline edit an input this way, i wrote a clickOutside directive and it works fine but in my example when i click to edit editMode becomes true and immediately input is shown and ...

i'm trying to inline edit an input this way, i wrote a clickOutside directive and it works fine but in my example when i click to edit editMode becomes true and immediately input is shown and ...

  1. input inline edit
  2. lightning input inline edit
  3. inline edit input angular

I'm looking for same method like getElementsAtPosition(x,y) but instead of position I want to get all DOM for a given area (may be a rectangle). So it should look something like getAllElementsAtArea(...

I'm looking for same method like getElementsAtPosition(x,y) but instead of position I want to get all DOM for a given area (may be a rectangle). So it should look something like getAllElementsAtArea(...

  1. jquery override javascript function