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
https://plnkr.co/edit/mDqbExlEBzb7EalN?preview

By admin

Leave a Reply

Your email address will not be published. Required fields are marked *