aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--signald/main.py43
1 files changed, 41 insertions, 2 deletions
diff --git a/signald/main.py b/signald/main.py
index 75eb8a9..48901f4 100644
--- a/signald/main.py
+++ b/signald/main.py
@@ -1,9 +1,14 @@
import json
+import cStringIO
import random
import re
import socket
+import base64
+
+from io import BytesIO
from typing import Iterator, List # noqa
+from PIL import Image
from .types import Attachment, Message
# We'll need to know the compiled RE object later.
@@ -154,13 +159,30 @@ class Signal:
block: Whether to block while sending. If you choose not to block, you won't get an exception if there
are any errors.
"""
+
+ # TODO: find out if sending them on non-images causes problems
+ width = 0
+ height = 0
+ preview = ""
+
+ # TODO: do for all images types
+ if filename.endswith("jpg") or filename.endswith("png"):
+ with Image.open(filepath) as img:
+ width, height = img.size
+ buffer = cStringIO.StringIO()
+ image.save(buffer, format="JPEG")
+ preview = base64.b64encode(buffer.getvalue())
+
payload = {
"type": "send",
"username": self.username,
"recipientAddress": recipient,
"attachments": [
{
- "filename": filename
+ "filename": filename,
+ "width": width,
+ "height": height,
+ "preview": preview
}
]
}
@@ -192,13 +214,30 @@ class Signal:
block: Whether to block while sending. If you choose not to block, you won't get an exception if there
are any errors.
"""
+
+ # TODO: find out if sending them on non-images causes problems
+ width = 0
+ height = 0
+ preview = ""
+
+ # TODO: do for all images types
+ if filename.endswith("jpg") or filename.endswith("png"):
+ with Image.open(filepath) as img:
+ width, height = img.size
+ buffer = cStringIO.StringIO()
+ image.save(buffer, format="JPEG")
+ preview = base64.b64encode(buffer.getvalue())
+
payload = {
"type": "send",
"username": self.username,
"recipientGroupId": recipient_group_id,
"attachments": [
{
- "filename": filename
+ "filename": filename,
+ "width": width,
+ "height": height,
+ "preview": preview
}
]
}