convert image url to base64 javascript

var xhr = new XMLHttpRequest();       
    xhr.open("GET", "/path/to/local/image/file", true); 
    xhr.responseType = "blob";
    xhr.onload = function (e) {
            console.log(this.response);
            var reader = new FileReader();
            reader.onload = function(event) {
               var res = event.target.result;
               console.log(res)
            }
            var file = this.response;
            reader.readAsDataURL(file)
    };
    xhr.send()

4
2
Riffer 90 points

                                    function encodeImageFileAsURL(element) {
  var file = element.files[0];
  var reader = new FileReader();
  reader.onloadend = function() {
    console.log('RESULT', reader.result)
  }
  reader.readAsDataURL(file);
}
<input type="file" onchange="encodeImageFileAsURL(this)" />

4 (2 Votes)
0
5
2

                                    function getBase64Image(img) {
  var canvas = document.createElement("canvas");
  canvas.width = img.width;
  canvas.height = img.height;
  var ctx = canvas.getContext("2d");
  ctx.drawImage(img, 0, 0);
  var dataURL = canvas.toDataURL("image/png");
  return dataURL.replace(/^data:image\/(png|jpg);base64,/, "");
}

var base64 = getBase64Image(document.getElementById("imageid"));

5 (2 Votes)
0
3.67
3
Cupcake 90 points

                                    function getBase64Image(src, callback, outputFormat) {
      const img = new Image();
      img.crossOrigin = 'Anonymous';
      img.onload = () => {
        const canvas = document.createElement('canvas');
        const ctx = canvas.getContext('2d');
        let dataURL;
        canvas.height = img.naturalHeight;
        canvas.width = img.naturalWidth;
        ctx.drawImage(img, 0, 0);
        dataURL = canvas.toDataURL(outputFormat);
        callback(dataURL);
      };

      img.src = src;
      if (img.complete || img.complete === undefined) {
        img.src = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
        img.src = src;
      }
    }

3.67 (3 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
how to get base64 from image url in javascript javascript read image and encode as base64 javascript format img src with base64 get image src url base64 javascript convert base64 to image locally in javascript js How to convert an image to Base64 encoding js mozilla convert image url src to base64 code how to get base64 string from image in javascript convert image to base 64 javascript how to convert image to base64 string in html and js js convert image from url to base64 js convert image from url to base 64 js img src from base64 convert base64 data to image javascript js data image base64 to file js upload base64 image js image base 64 convert to normal image base 64 convert to normal js image on base 64 convert to normal js shortening image base64 javascript image to base64 javascript npm how to convert uploaded image into base64 in javascript how to convert image web url to base64 in javascript base64 image convert javascript how to convert string image into base64 string using javascript js save base64 image javascript create imagedata from base64 javascript create image data from base64 how to encode and decode image to base64 in javascript javascript select image and convert to base64 image load from base64 string in js javascript how to convert image to base64 get a image from url and convert it base 64 node get image name from base64 javascript image convert to base64 in javascript website for convert image to base64 javascript javascript convert upload image to base64 js large image to base64 base64 encoded image javascript how to show image on page comes with base64 js how to shown image on page comes with base64 js javascript convert image input to base64 base64 string to image encode example in javascript base64 image encode example in javascript convert base64 url to image url javascript without canvas base64 string to image URL javascript base64string to imageURL javascript base64 to imageURL javascript javascript image url to base64url download image javascript base64 how to change base64 to image in js convert base64 string to jpeg image javascript send base64 image to server javascript how to convert base64 encoded string to image in javascript js image to base64 data data image base64 decode javascript convert base64 image url to image javascript convert image src path to base 64 string javascript convert image src to base64 string js convert image path to base64 string js img tag to base64 javascript base64 image to image javascript how to convert img file into base64 javascript convert jpeg to base64 javascript base64 string to image js javascript convert img tag to base64 how to convert imagedata to base64 javascript javascript convert string to base64 image convert image to bas64 based on url js image to bas64 javascript javascript convert image from url to base64 convert base64 string to image in javascript image to base 64 javascript save image from base64 with adois js typescript base64 encode image get base64 of image js read src image file in javascript to base64 how to convert image object to base64 javascript convert image file type to base64 url javascript button add imagem encode to base64 string javascript encode image to base64 string javascript how to change images in base 64 in typescript javascript get image data base64 upload base64 sting image in javascript How to upload base64-encoded image from JavaScript? javascript convert image to base64 how to convert image to base64 in javascript from a path how to convert image to base64 in javascript with zdonis js javascript convert base64 image to url how to convert image path to base64 javascript javascript get base64 value of image how to make image base64url in javascript how to create image from base64 in javascript convert image src to base64 js how to convert base64 data to image in javascript how to convert png jpg to base64 javascript encode image to base64 js base64 encoding image javascript convert an image to base64 javascript displaying base64 encoded image in html using javascrpt extract a base64 from url image javascript client base64 to image url js extract a base64 from url image javascript javascript return image to base64 string how to save base64 image in javascript turn image to base64 in js javascrip convet image uri to base 64 convert data:image/jpg;base64 in javascript image url from base64 data javascript js get base 64 from image url online convert image to base64 javascript src image convert into base64 javascript convert base64 to image and send it in javascript turn local image file url to base64 js convert to base64 javascript image image src to base64 javascript how to save a base64 to an image file javascript how to save an image from a base64 Javascript js base64 string to image how from base64 code create image File object js javascript base 64 image to image file upload base64 image javascript convert image to base64 javascript code convert image data array to base64 javascript convert to base 64 from img src javascript convert an image to base64 js javascript base64 image to src url javascript base64 image to src how to render an image from a base64 data in javascript javascript encode base64 img create image file from base64 string javascript javascript encode path to image to base64 javascript data:image/jpg;base64 save image base64 to image javascript convert image base64 to url in js converting images to base64 js image to base 64 js javascript url image to base64 js download base64 image ts new Image with base64 string how to convert base64 string into image in javascript preview base64 image + javascript base64 encode image url javascript imageURL to base64 javascript javascript download image base64 javascript image src from base64 node js convert image to base64 javascript upload image base64 javascript download image to base64 how to convert uploaded image to base64 in javascript decode image data into base64 using javascript encoding image to base64 javascript converter imagem para base64 javascript read image base64 javascript convert image heic to base64 error javascript turn image to base64 js convert a base64 string to image path js function to change base64 to image using javascript base64 for image js image to base64 html js How to convert a base64 image into a image file and upload js javascript image src returns base64 javascript image src is base64 javascript image src base64 convert img to base64 javascript base encode 64 javascript image js retrieve base 64 from image url convert base64 image tooriginal image javascript convert file image to base64 javascript javascript img to base64 how to convert img to base64 string in js javascript save base64 image convert image to base64 javascript to payload quick way to get base64 url from image javascript javascript display base64 image image to base64 javascript online javascript convert image file to base64 javascript pass base64 image to function javascript send base64 image to function How to convert base 64 image string to image in javascript javascript tobase64 image/jpg javascript set img src to base64 string how to convert image data to base64 in javascript javascript make image from base64 string js comprise base64 image string convert img file to base64 javascript convert jpg to base64 string javascript convert image to base64 javascript filereader javascript read image file as base64 base64 encode image from image src url javascript convert base64 in image js request image base64 from url javascript image link to base64 javascript convert base64 string to image file javascript javascript convert base64 image to image javascript base64 data uri to image convert image string to base64 javascript javascript get picture as base64 nodejs convert image to base64 base64 encode image in javascript javascript get image by url and convert base64 javascript to base64 image convert image to base64 js node convert base64 string to image javascript download image base64 data through url javascript download image from base64 javascript convert html dom to base64 image how convert image to base64 js image get base64 javascript convert image file into base64 javascript converting image file to base64 javascript upload image base64 javascript encode image base64 js download image base64 javascript create image from base64 javascript how to convert png image to base64 in javascript javascript img src base64 typescript convert image url to base64 transform image to base64 javascript convert base64 string into image javascript javascript base64 image encodeer how to save the image from url and convert to base64 js js img src base64 how to convert a base64 string to image in javascript get base64 image from url javascript convert from base64 to image i javascript how to convert image url to base64 in javascript convert image to base64 javscript javascript new image from base64 convert image to base64 uri and use in javascript convert image to base64 and use in javascript typescript base64 image choose image and convert it into base64 javascript choose image convert to base64 using javascript red image from url and convert to base64 javascript convert image to base64 javascript online turn img into base64 javascript transfer img from img to base64 js get base 64 of image js js edit image through base64 js transfer image to base 64 js transfer image to base64 does base64 work as an image source in javascript transfer img from url to base js javascript download image by browser convert to base64 base64 encoded string to image js image to base64 converter javascript encode base64 javascript image convert base64 image to image file javascript image base64 js js convert local image to base64 convert image to base64 string js convert base64 to image javascript and display how to convert local base64 image to string in javascript how to convert local image base64 to string in javascript how to convert image base64 to string in javascript convert local image to base64 string in javascript convert image to base64 bytes in javascript how to convert image file to base64 string in javascript get base64 image bytes in javascript how to encode base64 image in javascript save image as base64 javascript make image object base64 in js new image file from base64 javascript base64 image change bytes javascript edit image base64 javascript javascript get base 64 from image source javascript get base 64 from image file javascript pass image to base 64 read image file to base64 js how to convert base64 string into image in js js base64 to image file get image name from base64 string in javascript how to convert base64 to image in js how to make base64 into image url in js how to base64 encode an image in javascript encode image url to base64 javascript javascript send base64 as image file to server save base64 image to file javascript image upload base64 js javascript convert base64 to image image to base64 string in javascript display base64 image using url javascript base64 encode img data in js javascript get image base64 convert to an image to base64 javascript js save image from base64 convert base64 back to image javascript convert image base64 url to string javascript convert local image to base64 javascript with name convert img to base64 js convert image into base64 in javascript get image from base64 string javascript get image type from base64 string javascript get image type from base64 javascript convert a image to base64 javascript save base64 img javascript Local image to base64 JavaScript how to convert image to base64 node js js create base64 from image tag encode image base64 javascript javascript create image base64 javascript create image from base64 string javascript generate image base64 javascript image base64 src generate javascript image base64 src javascript string to base64 image javascript upload image and convert to base64 htmlcanvaselement to base64 image read image in base64 javascript convert base 64 URL to image javascript get base64 from image js javascript get base64 from image url javascript image url get base64 show base64 image in convas by js javascrpt convert url image to base64 javascript convert image url to base64 javscript iamge link to base64 image from base64 js js create base 64 image from local image send image as base64 javascript Convert image to base64 javascript large javascript send base64 image to server javascciprt image to base64 convert image to base 64 js new Image() from base64 js js get base64 from img change image to base64 javascript use of base64 encoding for images in javascript js-base64 encode image convert base64 image to url js turn base64 image into image js javascript get image from url and convert to base64 js convert image url to base64 convert image to base64 javascript img src base64 javascript upload js image to base64 base64 image javascript convert image to base64 typescript js write base64 to image javascript turn image to base64 javascript turn image into base64 javascript code to convert img tag to base64 without using toDataURL javascript code to convert img tag to base64 how to decode base64 image to images javascript encode image to base64 jhs obtain image from base64encode string javascript obtain image from base64encode javascript convert image from base64 javascript create an image from image base 64 js ask and convert image to base64 js javascript pictures base64 or png javascript image from base64 Javascript Encode image in Base64 how to convert base64 to image file in javascript javascript image from url to base64 get image base64 js how convert image file in base64 with javascript how convert a image in base64 with javascript convert imag to base64 from dom base64 image encode javascript javascript convert image to base64 string convert img from dom to base64 js javascript convert image to base64 from URl javascript convert to base64 image upload image to base64 javascript convert image to base64 with js show image using base64 in javascript image url into base64 javascript image from server to base64 javascript change image into base64 javascript url image to base64 javascript js download image base64 capture image and convert it to base64 js javascript create image object from base64 js image file to base64 javascript image from base64 str how to download and convert image into base64 string using javascript js base64 image js get base64 image base encode image js js image url to base64 how to convert img to base64 with js? fetch image from url and convert to base64 javascript get image from url and convert to base64 javascript take image and base 64 javascript how to convert base64 string to image in javascript js base64 encode image javascript upload image to base64 convert image from dom to base64 how to assign image of base64 to a variable in javascript image url to base64 js javascript image file to base64 data image base64 js how to save base64 as jpeg image to local using javascript javascript convert image buffer to base64 javascript encode image to base 64 how to send convert base64 image data in jpeg in javascript Convert base64 to image url javascript base64 convert into image js base64 to image base64 javascript how to use base64 to encode an image in javascript image base64 javascript how to convert an image to base64 in javascript convert image url to base64 typescript convert image url to base64 in javascript using local source convert image location to base64 in javascript using local source convert image to base64 in javascript using local source convert image to base64 in javascript from local directory convert image to base64 in javascript function assign to variable convert image to base64 in javascript function decode image to base64 javascript how to convert base64 image javascript how to display image from base64 string in javascript how to convert image to base64 using javascript convert image to base64 on reader javascript javascript upload image convert to base64 how to convert image into base64 in javascript upload image and convert to base64 javascript javascript image convert to base64 javascript use base64 image data for image how to convert image from windows to base64 in javascript js image to base64 url convert image to base64 string javascript with url how image to base64 js image convert to base64 js javascript code encode image to base64 from url javascript display image from base64 string javascript image base64 convert image to base64 in js image to base64 typescript how to encode an image in base64 javascript encode base64 image javascript base64 js image javascript image url to base64 convert image from url to base64 javascript image url to base64 javascript javascript show image from base64 convert multiple image to base64 javascript without canvas choose and convert image to base64 javascript get image by base64 from url get image base64 in js how to convert dom image to base64 convert uploaded image to base64 javascript image file to base64 javascript remote url to base64 javascript url to base64 react js getbase64image from url javascript convert long url to base64 how to get base64 from image in javascript js image from url to base 64 decode encode base64 javascript images convert jpg to string from images from path ./image javascript canvas ase64 image javascript filereader image to string js code get base64 image from url get base64 png val js url image to base64 how to decode base64 string to image in javascript javascript function to convert image to base64 step convert image into base64 javascript data url to base 64 javascript image from url to base64 how to get url from base64 convert base64 image to jpg javascript base64 to jpg javascript replace data:image/jpeg;base64 from base64 string javascript convert image to string in js image.onload return base64 url in js typescript image uri encode filereader covert jpg to string how to convert url to base64 in javascript converting image string to href convert image base64 javascript js convert img to string img url into base 64 convert url in base64 convert image path to base64 typescript base64 imageurl base64 to image url converter react dataurl to base64 js js convert base64 to image typescript url to base64 convert image url to base64 javascript convert a div text block into base64 image js convert a text block into base64 js image to base64 javascript func base64 in front of a img javascript convert jpg to string base64 in javascript js url img to base64 js url img to base564 turn images to data javascript javascript change url link to base64 converting image to base64 javascript base64 encode jpg javascript convert image file to base64 string javascript convert image file to base64 js convert image to base64 string in javascript javascript base64 image url encode javascript base64 image url encode function encode url to base64 javascript function encode image url to base64 javascript function encode image to base64 javascript function encode image to bse64 javascript function convert image data to base64 encoder javascript convert image link to base64 get base 64 of image link js convert external link to base64 javascript get base 64 image then how to convert image url to base64 js generate base64 image how to get an image link after creating it with base64 base64 to img link javascript convert imagefrom base64 to link javascript convert base64 image to link javascript convert bse 64 image to link javascript image object to base64 javascript how to convert url to base64 how to convert http image to base64 in react js convert image url to base64 reactjs convert image in base64 javascript turn image into base64 js javascript load base64 encoded image to display convert local image to base64 javascript convert base64 to image file using javascript create image from base64 using javascript convert base64 to image javascript and download convert jpg to string javascri t convert jpg to string display jpg from server javascript convert jpg png to string from server database javascript convert jpg png to string javascript from server convert png image to base64 string in node js url to base64 image How to convert image into base64 string using JavaScript? nodejs base64 image to image javascript save base64 image to file javascript image as base64 from file how to convert an image to base64encodedimage in javascript convert image tag src to base64 javascript convert image source to base64 js convert image source to base 64 js convertir base64 a imagen javascript console log data url base64 image to base64 in javascript js convert gif string to file get data from url and convert to base64 javascript convert jpg to base64 javascript image from file to base64 string javascript image to base64 string javascript image to base64 javascript example js create base64 image create src from base64 string javascript using base64 images in to javascript base64encode in js image image to base64 javascript scr= js library convert image source website url to base64 js library convert image source url to base64 how to convert image source tobase64 convert png image url to base64 reactjs convert image to icon typescript convert remote http url to base64 javascript convert remote url to base64 javascript Get image from base64 string in Javascript base64 like image javascript Convert Your Image to Base64 api how to convert base64 to image in javascript how to convert image file to base64 in javascript node js convert image url to base64 decode from frontend bas64 img // Logo converted to base64 js convert image url to base 64 img to base64 converter js converting file from url to base64 convertIng To Base64URL without callback image file path to data url typescript how to convert image to string in javascript FileReader() how to convert image to string in javascript base64 string to image javascript base64 to image javascript convert image url to image js javascript convert image to base 64 js convert image to base64 string js get image base64 from url base64 image from url link js convert img to base64 base64 to image js jquery get background image url and convert to base64 get base 64 image from url js image data to base64 convert dataurl to base64 convert input image to base64 javascript base64.encode image in javascript convert image url to base64 in javascript convert url link to base64 javascript base64 from url javascript encode base64 image from url javascript javascript function image encode base64 js base64 to image js read external image file as base64 jpeg base64 javascript convert base64 to image javascript base64 image to text javascript how to get base64data of image from url convert url image to base64 javascript return base64 of image javascript get base64 of image convert image to javscirpt javascript encode base64 image python replace image url to base64 convert image to base64 javascrip img to base64 js external image url to base64 js convert img src to base64 javascript src to base64 javascript convert image src to base64 javascript get image in base64 nodejs read file as base64 to <img src /> javascript png file to base64 get image by url and convert to base64 vjavascript convert url to base64 base64 encode image js javascript generate base64 out of canvas javascript convert image to base54 js image 64 from link how to convert png file into base64 encoder using typescript Convert Image url To Base64 String Using JQuery javascript get base 64 url from event url in base 64 images javascript angular convert image to base64 todataurl (base64 data) with jquery js codes change image to base64 convert image url to base64 js encode image to base64 js encode png image to base64 react convert image from url to base64 javascript encode image convert image to string in javasctipt image url to base64 reactjs conver file url to base 64 ways to convert image to base64 javascript convert urldata to base64 unction toDataURL(url, callback) create base64 image javascript convert image to base64 string javascript img onload convert base64 image onload get base64 get base64 from url image how to get base 64 by url get base64 from image cdn url jpg to base64 + javscript js image get base64 image url to base64 convert image to base64 in javascript js encode image base64 js get base64 from image base64 from url js base 64 from url js get base64 from url convert img tag to base64 javascript javascript base64 image javascript get base64 from url convert image data to base64 javascript javascript base64 jpeg javascript recieve base64 image return image javascript from base 64 base64 encode image javascript convert image from local url to base64 how to share base64 image in html jav get base64 from file url convert image response to base64 javascript how to convert image to base64 string in javascript convert img url to base64 javascript js jpg to base64 convert img src to base64 javascript how to convert to string a image src javascript convert image src to base64 javascript get image from src img and conver it to base64 using javascript encode image from src to base64 string javascript get base64 from image javascript image to base64 using javascript base64 encode image in javascript decode convert dataurl to base64-encoded string convert dataurl to base64 Encoded string get base64 of image javascript how to encode an image into base64 in javascript base64 image encoder javascript encode image file in js how to turn img tag to base64 get image by base64 js create url image from base64 convert image file to base64 javascript convert image to base64 encoded string javascript open image from imageurl data:image/jpg;base64 javascript javascript load image from url to base64 javascript to convert image to base64 convert image into base64 javascript transform url to image object convert png to base64 js image to string javascript convert image to base64 js get a file base64 from url javascript get a file base64 from url how to convert string data url to image in javascript how to convert an image-string to picture src how to convert an image string to src js-base64 image base64 encode image library javascript javascript convert image from base64 to url how to get an image from an url and convert it to a base64 how to get an image from url and convert to a base64 how to convert base64 data to local url path in js javascript get image base64 from url how to get base64 string of image from address link base 64 to image code in js url to base64 js how to convert png to base64 javascript js png to base64 string js image to base64 React convert image url to base64 js image base64 canvas base64 image converter url image convert to base64 javascript javascript file url to base64 javascript comnvert image to base 64 javascript get image base 64 convert url to base64 javascript base64 to image url javascript javascript convert image data to base64 jquery convert image url to base64 image javascript convert file from url to dataurl convert image link to base64 javascript convert image to string javascript javascript encode image to base64 conver image ti base 64 js url to base64 javascript javascript convert image to base64 javascript convert image path to base64 javascript how to integrate the image to base64 converted image in the javascript how to integrate the image to ase 64 converted image n the javascript js base 54 to img convert image into base64 string javascript js to base64 image javascript read image url to base64 create image out of base64 javascript convert file url to base64 javascript get image from base64 javascript javascript imagedata to base64 how to get image base64 data in js on change event base64 to url js javascript base64 encode image js convert url to base64 image to image encoding js convert png file to base64 javascript src to base64 js convert to jpeg/base64 string javascript javascript todataurl image 64 bit how to convert an uploaded image in html to a 64bit string in javascript how to return base 64 version of image js javscript convert image to base64 converting remote file to base64 angular typescript convert UTF-8 encode image to image get image base64 javascript javascript convert png to bas 64 convert base64 encoded to image javascript decode a base64 encoded image javascript javascript parse image file to string easy image to base 64 javascript convert png to base 64 javascript png to base 64 javascript how to convert image into base64 string using javascript javascript image to base64 js image png to base64 js base64 from image convert png to base javascript get base64 string from image javascript png to base64 js js load image to base64 get image path from base64 encoded string in javascript png to base64 javascript javascript convert image to base64 image to base64 js encode image to base64 javascript encode and decode image to base64 javascript how to get image from base64 string in javascript how to convert and save base64 data into jpg images in vanilla js how to convert image to base64 in javascript convert raw png to base64 js convert png to base64 javascript javascript canvas convert image to base64 js convert image to base64 img to string javascript convert image to base64 using javascript get base64 string from data uri javascript if data url or base64 javascript file url to base64 javascript convert image to base64 javascript js image to base64 image to base64 javascript example image base64 string convert image to base64 image c# how to encode a string using the base64 convert string to encryption in php convert an image into Base64 string using JavaScript
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source