import { Component } from ‘@angular/core’;
@Component({
selector: ‘my-app’,
templateUrl: ‘./app.component.html’,
styleUrls: [ ‘./app.component.css’ ]
})
export class AppComponent {
name = ‘Angular’;
constructor(){
this.toDataURL(‘https://pbs.twimg.com/profile_images/558329813782376448/H2cb-84q_400x400.jpeg’, function (dataUrl) {
console.log(dataUrl)
})
}
toDataURL(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onload = function () {
var reader = new FileReader();
reader.onloadend = function () {
callback(reader.result);
}
reader.readAsDataURL(xhr.response);
};
xhr.open(‘GET’, url);
xhr.responseType = ‘blob’;
xhr.send();
}
}
https://stackoverflow.com/questions/57155825/converting-an-image-url-to-base64-in-angular