[Vobject] Embedding a photo into vcard

Markus Eberle markus.eberle at tngtech.com
Tue Dec 30 04:24:12 CST 2008


Hi,

(I am doing a full quote to have a nearly complete example :-))

> 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?

You are right, i have copied the code from some methods, and the  
"getvalue()" got lost somehow...

> 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.

This would really be great! I took a look at the vobjects-code, but as  
I am quite new with Python this is far beyond my knowledge...
Sorry.

Cheers & Thanks for the great work.
     Markus


More information about the VObject mailing list