[Vobject] Embedding a photo into vcard

Markus Eberle markus.eberle at tngtech.com
Mon Dec 29 06:05:35 CST 2008


hmm.. should have written the mail earlier ;-)

Ok, the problem seems to be the line wrap on the first line of the  
photo:

N:Eberle;Markus;;;
PHOTO;TYPE=JPEG;ENCODING=BASE64:/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAgGBgcG
   
BQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC
  4zNDL/ 
2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIy
  MjIyMjIyMjIyMjIyMjIyMjL/wAARCAFSAOYDASIAAhEBAxEB/ 
8QAHwAAAQUBAQEBAQEAAAAAAA

So the first line (containing also the encoding information) is too  
short.
If it has the same (content) length like the other lines the MacOS- 
Addressbook will recognize the photo (see a working example below).
 From my point of view the problem is the serialization of the photo  
which also uses the 'foldOneLine' function. This wraps the lines at 75  
characters.

To fix it, it would be great if the photo behaviour would either do  
not wrap the line at all (whole photo string in one line) or write it  
like addressbook.

Cheers,
     Markus

Working photo:

PHOTO;BASE64:
   /9j/4AAQSkZJRgABAQAAAQABAAD/ 
4hEsSUNDX1BST0ZJTEUAAQEAABEcYXBwbAIAAABtbnRyUkdC
    
IFhZWiAH2AAEAAUADQAiABRhY3NwQVBQTAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA9tYAAQAA
   AADTLWFwcGxDGYn4wj5ca/tnOh/ 
ayFOhAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA5y
    
WFlaAAABLAAAABRnWFlaAAABQAAAABRiWFlaAAABVAAAABR3dHB0AAABaAAAABRjaGFkAAABfAAA


P.S.: My current solution now takes the serialized vcard and modifies  
the Photo-element to have all content in one line.

Am 29.12.2008 um 10:35 schrieb Markus Eberle:

> Hi,
>
> 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)
>
> Cheers,
>     Markus
> _______________________________________________
> VObject mailing list
> VObject at lists.skyhouseconsulting.com
> http://lists.skyhouseconsulting.com/mailman/listinfo/vobject
>

-- 
Markus Eberle
TNG Technology Consulting GmbH
markus.eberle at tngtech.com

TNG Technology Consulting GmbH, Betastr. 13a, 85774 Unterfoehring
Geschaeftsfuehrer: Henrik Klagges, Gerhard Mueller, Christoph Stock
Amtsgericht Muenchen, HRB 135082



More information about the VObject mailing list