There are multiple ways in which you can convert an image into its Base64 String, one of those ways is using Canvas,
Example:<!html>
<head>
<title>Image to Base64 String Example: Code2care.org</title>
</head>
<body>
<h2>Image Displayed using IMG Tag:</h2>
<img src="code2care-logo.jpg" id="myImg" alt="myImg"/>
<h2>Image Displayed using Base64 String Tag:</h2>
<div id="myImg64" alt="myImg64"></div>
<script type='text/javascript'>
var image = document.getElementById('myImg');
var canvas = document.createElement('canvas');
canvas.getContext('2d').drawImage(image, 0, 0, image.naturalHeight, image.naturalWidth);
var base64ImageString = canvas.toDataURL();
document.getElementById("myImg64").innerHTML = base64ImageString;
</script>
</body>
</html>

-
Have Questions? Post them here!
More Posts related to JavaScript,
- How to get UTC (GMT) time using JavaScript
- Submit html form on dropdown menu value selection or change using javascript
- How to detect Browser and Operating System Name and Version using JavaScript
- JavaScript : Get current page address
- [javaScript] Convert text case to lowercase
- How to check if a String contains substring or a word using javaScript
- Writing your first Hello, World! 🌍 JavaScript code Tutorial
- JavaScript: Check if variable is a number
- How to send email from JavaScript HTML using mailto
- Meaning of javascript:void(0) explained with example
- How to get query string in JavaScript HTML location.search
- Javascript convert text case from uppercase to lowercase
- Loading previous page using html button using JavaScript
- JavaScript : Get url protocol HTTP, HTTPS, FILE or FTP
- How to get current URL Location using Javascript HTML
- Detect if Cookies are enabled using JavaScript
- Write javaScript code in Swedish using FikaScript
- Add Animated Scrolling to Html Page Title Script
- JavaScript: Convert an Image into Base64 String
- Remove items from JavaScript array
- Send Extra Data with Ajax Get or Post Request
- How to Print from JavaScript HTML using window.print
- Get Device Screen Width and Height using javaScript
- Examples: Convert String to int in JavaScript
- npm WARN saveError ENOENT: no such file or directory, open /mnt/c/package.json
More Posts:
- List of Java Simple Date Formats (Cheatsheet) - Java
- Python Program To Calculate Simple Interest (SimpleInterest.py) - Python
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error - Android
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server - Java
- Hide files and folders on Mac OS X - Mac-OS-X
- [Solution] The connection to the remote PC was lost, preparing to reconnect - Windows RDP - Windows
- Make Bootstrap Button look like a link - Bootstrap
- How to Copy Entire Directory to another Directory in Linux - Linux