grazie mi hai salvato!
codice:
creaVcf(): void {
const imgProfile = (<HTMLImageElement>document.getElementById("img_profile"));
const canvas = document.createElement("canvas");
canvas.width = imgProfile.width;
canvas.height = imgProfile.height;
const ctx = canvas.getContext("2d");
ctx.drawImage(imgProfile, 0, 0);
const dataURL = canvas.toDataURL("image/jpeg");
const blobImg = dataURL.replace(/^data:image\/?[A-z]*;base64,/, '');
const makeVCardVersion = `VERSION:3.0`;
const makeVCardInfo = `N:${this.nome};${this.cognome}`;
const makeVCardName = `FN:${this.nomeCognome}`;
const makeVCardOrg = `ORG:${this.azienda}`;
const makeVCardTitle = `TITLE:${this.ruolo}`;
const makeVCardPhoto = `PHOTO;TYPE=JPEG;ENCODING=b:${blobImg}`;
const makeVCardTel = `TEL;TYPE=WORK,VOICE:${this.telefono}`;
const makeVCardAdr = `ADR;TYPE=WORK,PREF:;;${this.indirizzo}, ${this.cap} ${this.citta}`;
const makeVCardEmail = `EMAIL:${this.email}`;
const makeVCardTimeStamp = `REV:${new Date().toISOString()}`;
let vcard = `BEGIN:VCARD
${makeVCardVersion}
${makeVCardInfo}
${makeVCardName}
${makeVCardOrg}
${makeVCardTitle}
${makeVCardPhoto}
${makeVCardTel}
${makeVCardAdr}
${makeVCardEmail}
${makeVCardTimeStamp}
END:VCARD`;
const file = new Blob([vcard], {type: 'text/vcard'});
const a = document.createElement('a');
a.href = URL.createObjectURL(file);
a.download = this.nomeCognome + '.vcf';
a.click();
URL.revokeObjectURL(a.href);
}
l'unica modifica che ho fatto è nel replace:
codice:
const blobImg = dataURL.replace(/^data:image\/?[A-z]*;base64,/, '');
e poi nell'immagine sulla pagina il crossorigin:
codice:
<img id="img_profile" src="{{img}}" alt="{{nomeCognome}}" style="width:100%;height: 100%;" crossorigin="anonymous">
grazie mille!!