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

Open
Agno94 opened this issue Jan 13, 2017 · 4 comments
Open

Add photo support #107

Agno94 opened this issue Jan 13, 2017 · 4 comments
Labels

Comments

@Agno94
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).

@lucc

This comment has been minimized.

Copy link
Collaborator

@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 carddav_object.py line 68 that might be relevant.

How should khard handle the field? (Scenarios?)

@thfi

This comment has been minimized.

Copy link
Contributor

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

@potuz

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/carddav_object.py b/khard/carddav_object.py
index b2d066d..943c878 100644
--- a/khard/carddav_object.py
+++ b/khard/carddav_object.py
@@ -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:
                 organisations.append(child.value)
         return sorted(organisations)
 
+    def add_photo(self, photo):
+        photo_obj = self.vcard.add('photo')
+        photo_image = Image.open(photo)
+        photo_jpg = BytesIO()
+        photo_image.save(photo_jpg, "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:
             else:
                 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
         self.delete_vcard_object("ORG")
diff --git a/khard/helpers.py b/khard/helpers.py
index 461c7a6..dc09faa 100644
--- a/khard/helpers.py
+++ b/khard/helpers.py
@@ -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
@alex3kov

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
Projects
None yet
5 participants
You can’t perform that action at this time.