aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorniklas <niklas@niklashalle.net>2020-09-20 15:01:20 +0200
committerniklas <niklas@niklashalle.net>2020-09-20 15:01:20 +0200
commit16075b15d4e76364dbb960ecb239e46e3501dc18 (patch)
tree67f2907ccb8cdb01db33dfa16f5c9c15c82f5d61
parent64a3de18188aae3c9376bb50a542ee26ca1bb65c (diff)
downloadpysignald-master.tar.gz
pysignald-master.zip
maybe add correct dimensions and previewHEADmaster
-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
}
]
}