convert an image into Base64 string using JavaScript
JavaScript
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;
}
}
Also in JavaScript:
- Title
- angular lifecycle hooks
- Category
- JavaScript
- Title
- How to check whether a string contains a substring in JavaScript?
- Category
- JavaScript
- Title
- find index of object in array javascript
- Category
- JavaScript
- Title
- Programação web com Node e Express Beneficiando-se da stack JavaScript
- Category
- JavaScript
- Title
- angular google maps
- Category
- JavaScript
- Title
- Javascript - Track mouse position
- Category
- JavaScript
- Title
- express bodyparser deprecated
- Category
- JavaScript
- Title
- angular form validation
- Category
- JavaScript
- Title
- compress string javascript
- Category
- JavaScript
- Title
- ajax open a request
- Category
- JavaScript
- Title
- how to limit input type max length
- Category
- JavaScript
- Title
- javascript array of objects access properties
- Category
- JavaScript
- Title
- find class using jquery
- Category
- JavaScript
- Title
- javascript button onclick
- Category
- JavaScript
- Title
- brute force search javascript
- Category
- JavaScript
- Title
- how to find the index of a value in an array in javascript
- Category
- JavaScript
- Title
- async await arrow function
- Category
- JavaScript
- Title
- iterate over object javascript
- Category
- JavaScript
- Title
- combine two arrays javascript
- Category
- JavaScript
- Title
- array insertion javascript
- Category
- JavaScript
- Title
- export aab bundle react native android
- Category
- JavaScript
- Title
- javascript change attribute
- Category
- JavaScript
- Title
- javascript click button by id
- Category
- JavaScript
- Title
- angular run with proxy
- Category
- JavaScript
- Title
- .push js
- Category
- JavaScript
- Title
- get text in select jquery
- Category
- JavaScript
- Title
- javascript check if variable is number
- Category
- JavaScript
- Title
- function inside a class component react
- Category
- JavaScript
- Title
- handling event in jsx
- Category
- JavaScript
- Title
- electron Uncaught ReferenceError: require is not defined at recorder.js:1
- Category
- JavaScript
- Title
- capitalize all letters jquery
- Category
- JavaScript
- Title
- detect a click outside an element javascript
- Category
- JavaScript
- Title
- daterangepicker set maxdate
- Category
- JavaScript
- Title
- bootstrap 4 hide modal via javascript
- Category
- JavaScript
- Title
- firestore update array
- Category
- JavaScript
- Title
- angular @Output()
- Category
- JavaScript
- Title
- How do I check whether a checkbox is checked in jQuery?
- Category
- JavaScript
- Title
- javascript clearinterval
- Category
- JavaScript
- Title
- how to get unique values from array in javascript without duplicate value
- Category
- JavaScript
- Title
- getting value from radio button javascript
- Category
- JavaScript
- Title
- get selected option value
- Category
- JavaScript
- Title
- insert into specific array index that has a value existing on that index
- Category
- JavaScript
- Title
- javascript check empty object
- Category
- JavaScript
- Title
- How do you start a Node Application, if the entry file is index.js:
- Category
- JavaScript
- Title
- command to start api on react
- Category
- JavaScript
- Title
- how to push object in array using for loop javascript
- Category
- JavaScript
- Title
- check undefined object javascript one liner set to emtpy
- Category
- JavaScript
- Title
- get parent element using jquery
- Category
- JavaScript
- Title
- get current time epoch javascript
- Category
- JavaScript
- Title
- angular delete from array by name
- Category
- JavaScript
- Title
- array spread operator in javascript
- Category
- JavaScript
- Title
- client timezone offset in JavaScript
- Category
- JavaScript
- Title
- how to delete a variable in js
- Category
- JavaScript
- Title
- is game development with javscript wrth it ?
- Category
- JavaScript
- Title
- edje js not pre compile for node 12 version
- Category
- JavaScript
- Title
- generate unique id javascript
- Category
- JavaScript
- Title
- binary to int javascript
- Category
- JavaScript
- Title
- create a react native project
- Category
- JavaScript
- Title
- get location from brwoser react
- Category
- JavaScript
- Title
- change title react
- Category
- JavaScript
- Title
- javascript array split chunk
- Category
- JavaScript
- Title
- how to disable cash through get request in angular
- Category
- JavaScript
- Title
- how to concatenate strings and variables in javascript
- Category
- JavaScript
- Title
- howt to convert 2020-02-01T08:54:07.284Z to date in javascript react
- Category
- JavaScript
- Title
- find highest number in array javascript
- Category
- JavaScript
- Title
- Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead javascript
- Category
- JavaScript
- Title
- cannot read property 'props' of undefined react redux functional component
- Category
- JavaScript
- Title
- array map javascript
- Category
- JavaScript
- Title
- convert string to char array javascript
- Category
- JavaScript
- Title
- how to add property to object in javascript
- Category
- JavaScript
- Title
- how to map over arrays vuejs
- Category
- JavaScript
- Title
- find particular object from array in js
- Category
- JavaScript
- Title
- convert class object to json python
- Category
- JavaScript
- Title
- CSRF token in js
- Category
- JavaScript
- Title
- how to sepaarte text in object javascript
- Category
- JavaScript
- Title
- generate random ip address javascript
- Category
- JavaScript
- Title
- box shadow javascript style change
- Category
- JavaScript
- Title
- clear formarray in angular 6
- Category
- JavaScript
- Title
- how to remove session data on tab close in redux\
- Category
- JavaScript
- Title
- dropzone add download button
- Category
- JavaScript
- Title
- ejs current year
- Category
- JavaScript
- Title
- how to write a program that shows a random number between 1 and 100 in your browser
- Category
- JavaScript
- Title
- how to have your discord bot send two message
- Category
- JavaScript
- Title
- javascript class click event
- Category
- JavaScript
- Title
- Enclose in Brackets
- Category
- JavaScript
- Title
- compare two arrays javascript
- Category
- JavaScript
- Title
- array javascript django
- Category
- JavaScript
- Title
- import json file javascript
- Category
- JavaScript
- Title
- javascript check if text is overflowing
- Category
- JavaScript
- Title
- how to craete a shopping cart in node js
- Category
- JavaScript
- Title
- change text of element js
- Category
- JavaScript
- Title
- javascript append to object
- Category
- JavaScript
- Title
- AJAX JAVASCRIPT TUTORIALS
- Category
- JavaScript
- Title
- how to make an async function
- Category
- JavaScript
- Title
- javascript array flatten
- Category
- JavaScript
- Title
- does a function inside a function need to be called?
- Category
- JavaScript
- Title
- get the state of a checkbox
- Category
- JavaScript
- Title
- export to logs to elasticsearch node from fluend container k8s
- Category
- JavaScript
- Title
- hover jquery
- Category
- JavaScript
- Title
- createnodefield
- Category
- JavaScript