[Vobject] Embedding a photo into vcard

Jeffrey Harris jeffrey at osafoundation.org
Mon Dec 29 15:59:58 CST 2008


Hi Markus,

> I am trying to use python and vobject to create vcards which contain  
> photos.
> I can create a vcard which contains the base64 encoded photo but the  
> Apple Addressbook won't recognize the photo.
> 
> Perhaps some one can give me a hint how to embedd a photo into a vcard.
> 
> Currently I am doing like:
> 
>              card.add('photo')
>              card.photo.value = jpg
>              card.photo.encoding_param = "b"
>              card.photo.type_param = "JPEG"
> 
> where 'jpg' is
> 
>              i = Image.open(input)
>              jpg = StringIO.StringIO()
>              i.save(jpg, "JPEG")
> 
> (when writing 'jpg' to a file, it is recognized as a correct JPG-image)

One note, for search engine posterity:  This all looks good, except that
when you do:

card.photo.value = jpg

presumably you meant to do:

card.photo.value = jpg.getvalue()

since jpg is a StringIO, not a plain old string?

Sincerely,
Jeffrey

P.S. I'd be delighted if someone wanted to enhance the rudimentary Photo
behavior to handle a PIL object when serializing, and to transform
parsed images into their PIL form.  Then you could just do:

card.add('photo').value = i

and everything would work out nicely.


More information about the VObject mailing list