If you want to export vCards in your Ruby on Rails application, chances are you’ve probably stumbled upon vPim. The documentation claims that you’re able to include an image in a vCard by adding the following to your code:
maker.add_photo do |photo|
photo.image = File.open(path_to_image).read
photo.type = 'jpeg'
end
The only problem is that it does not work in the Address Book app of Mac OS X, on a Nokia phone etc. The picture included in the vCard is simply not shown.
The solution is for you to do a minor manual change of the string that your card object turns into when it is serialized by the encode method. 1) You include image data via PHOTO;BASE64:[...], and 2) you make sure that the base64 data is inserted correctly in the vCard file.
If we presume that you wish to include an image, YOUR_IMAGE.jpg, placed in the /public folder in your rails application, you can make use of the following piece of code:
my_vcard = card.encode.sub("END:VCARD", "PHOTO;BASE64:" + "\n " + [File.open(Rails.public_path + 'YOUR_IMAGE.jpg').read].pack('m').to_s.gsub(/[ \n]/, '').scan(/.{1,76}/).join("\n ") + "\nEND:VCARD")
If you use the above piece of code, you’ll see that the bottom line of the generated vCard, END:VCARD, is replaced by a PHOTO section containing your image data, correctly formatted and inserted in base64 format (and of course, END:VCARD is added in the end).
If you then wish to send the freshly generated vCard to the user’s browser, you type in the following:
send_data(my_vcard, :type => 'text/x-vcard;', :filename => 'my_vcard.vcf', :disposition => 'attachment')
Et voila, now vCard export works with images. In Address Book on Mac OS X, our vCard can look like this:

A contact in Address Book on Mac OS X (don't mind the Danish text). Notice the use of the contact icon that is also used in Meeho!™.