Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add photo support #107

Agno94 opened this issue Jan 13, 2017 · 4 comments

Add photo support #107

Agno94 opened this issue Jan 13, 2017 · 4 comments


Copy link

@Agno94 Agno94 commented Jan 13, 2017

Both in khard.carddav_object.CarddavObject and in the templates there is no fields for photo property.
Photo property is an uri (maybe more simple) or a base64 encoded file(maybe more difficult).


This comment has been minimized.

Copy link

@lucc lucc commented Jan 13, 2017

What happens if you import/edit/list a vcard file with a photo field in it? What should happen instead? There is a comment in line 68 that might be relevant.

How should khard handle the field? (Scenarios?)


This comment has been minimized.

Copy link

@thfi thfi commented Jun 10, 2017

Idea: Render images via aalib or libcaca in list mode. In edit mode, add the image as comment to the temporary file one edits.


This comment has been minimized.

Copy link

@potuz potuz commented Jun 29, 2017

It would be nice to be able to add photos to newly created vcards. I quickly cooked the following patch that works to add a PHOTO rule to vcards version 3.0. In just a couple of tests it works here which is all I need. It takes an argument of the form Photo : /path/to/file.jpg

diff --git a/khard/ b/khard/
index b2d066d..943c878 100644
--- a/khard/
+++ b/khard/
@@ -17,6 +17,9 @@ import yaml
 from . import helpers
 from .object_type import ObjectType
+from io import BytesIO
+from PIL import Image
 class CarddavObject:
@@ -345,6 +348,15 @@ class CarddavObject:
         return sorted(organisations)
+    def add_photo(self, photo):
+        photo_obj = self.vcard.add('photo')
+        photo_image =
+        photo_jpg = BytesIO()
+, "JPEG")
+        photo_obj.value = photo_jpg.getvalue()
+        photo_obj.encoding_param = "b"
+        photo_obj.type_param = "JPEG"
     def add_organisation(self, organisation):
         org_obj = self.vcard.add('org')
         org_obj.value = helpers.convert_to_vcard(
@@ -871,6 +883,10 @@ class CarddavObject:
                 raise ValueError(
                     "Error: nickname must be a string or a list of strings")
+        # photo
+        self.delete_vcard_object("PHOTO")
+        if bool(contact_data.get("Photo")):
+            self.add_photo(contact_data.get("Photo"))
         # organisation
diff --git a/khard/ b/khard/
index 461c7a6..dc09faa 100644
--- a/khard/
+++ b/khard/
@@ -363,6 +363,12 @@ def get_new_contact_template(supported_private_objects=[]):
         #       - category2
         Categories : 
+        # photograph
+        # may contain a single jpeg file
+        # format: 
+        #   Photo : /tmp/photo.jpg
+        Photo : 
         # web pages
         # may contain a string or a list of strings
         Webpage :
@lucc lucc added the enhancement label Jan 12, 2018

This comment has been minimized.

Copy link

@alex3kov alex3kov commented Jun 23, 2018

Having khard manage contact photos would be very nice, is there any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
5 participants
You can’t perform that action at this time.