brewster / vcardigan

Ruby vCard Builder/Parser
MIT License
71 stars 23 forks source link

vcard photo #18

Open akam-it opened 7 years ago

akam-it commented 7 years ago

Is it possible to attach photo to vcard? I tryed vcard = VCardigan.create vcard.photo File.binread("1.jpg") vcard.photo "TYPE=JPEG;ENCODING=b:" + Base64.encode64(File.binread("1.jpg"))

but unsuccessful

tfreedman commented 5 years ago

I just hit this today while attempting to programmatically add images to some vcards:

Base64.encode64 won't work as that has line breaks every so often which causes VCardigan to think you're attaching multiple broken images (as it thinks the photo is an array of text). Instead, use Base64.strict_encode64, which works fine.

Example:

photo = Base64.strict_encode64(some_file) vcard.photo photo, {:type => 'jpeg', :'ENCODING' => 'b'}

hashmaster3k commented 3 years ago

For anyone else running into issues this worked for me:

encoded_string = Base64.strict_encode64(File.open("icon.gif", "rb").read)
vcard.photo encoded_string, {:type => 'image/gif', :'ENCODING' => 'b'}