[Vobject] Unable to add photo to vcard (Address Book OS X 10.6.4)

Matthew Leingang leingang at courant.nyu.edu
Thu Sep 16 06:07:38 CDT 2010


Dear Roberto,

I don't remember why, but this is a tricky one to get working.  Here's what I do and it's worked for me:

            photo_fh=open(photo_filename,'rb')
            card.add('photo') 
            card.photo.value = photo_fh.read()
            card.photo.encoding_param = "b" 
            card.photo.type_param = "JPEG" 

No base64 encoding.

HTH,
Matthew Leingang



On Sep 16, 2010, at 5:22 AM, Roberto Aguilar wrote:

> Hello,
> 
> I'm trying to use the vobject python module to build a vcard with an embedded photo.  Using the code below, the photo does not show up.  I have tried setting vcard.wacky_apple_photo_serialize to True or False, but that does not help.  I've also tried different variations of the encoding_param, as well as adding/removing the photo type_param.
> 
> Additionally, taking a look at vcards with embedded photos, I manually removed the "encoding=" from the photo line, but still no dice.
> 
> Any help is greatly appreciated.
> 
> Thanks,
> -Roberto.
> 
> #!/usr/bin/env python
> 
> import base64
> import sys
> 
> import vobject
> from vobject import vcard
> vcard.wacky_apple_photo_serialize = False
> 
> card = vobject.vCard()
> 
> card.add('n')
> card.n.value = vobject.vcard.Name(family='smith', given='john')
> 
> card.add('fn')
> card.fn.value = 'John Smith'
> 
> filename = sys.argv[1]
> f = open(filename)
> data = f.read()
> f.close()
> 
> b64 = base64.encodestring(data)
> 
> card.add('photo')
> card.photo.value = b64
> #card.photo.type_param = 'JPEG'
> card.photo.encoding_param = 'b'
> 
> outfile = sys.argv[2]
> f = open(outfile, 'wb')
> f.write(card.serialize())
> f.close()
> _______________________________________________
> VObject mailing list
> VObject at lists.skyhouseconsulting.com
> http://lists.skyhouseconsulting.com/mailman/listinfo/vobject
> 

-- 
Matthew Leingang                             |  leingang at courant.nyu.edu
Clinical Associate Professor of Mathematics  |  Vice Chair for Undergraduate Affairs
Courant Institute of Mathematical Sciences   |  Department of Mathematics



More information about the VObject mailing list