Skip to content

Commit

Permalink
Set width and height on camera responses. Fixes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
turt2live committed Feb 2, 2017
1 parent fcee36c commit 0137e65
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
10 changes: 7 additions & 3 deletions plugins/cameras.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from neb.plugins import Plugin
from neb.engine import KeyValueStore
from requests.auth import HTTPBasicAuth
from io import StringIO
from PIL import Image

import logging as log
import requests
import io


class CameraCheckPlugin(Plugin):
Expand Down Expand Up @@ -65,16 +66,19 @@ def get_image(self, shortcode):
apiInfo = self.store.get("api")
url = apiInfo["base_url"] + "/image/" + shortcode + "?q=40"
result = requests.get(url, auth=HTTPBasicAuth(apiInfo["username"], apiInfo["password"]), stream=True)
#capture = Image.open(StringIO(result.content))
capture = Image.open(io.BytesIO(result.content))
response = self.matrix.media_upload(result.content, "image/jpeg")
log.debug(response)
if "content_uri" in response:
return {
"msgtype": "m.image",
"url": response["content_uri"],
"body": shortcode + ".jpg",
"info": {
"mimetype": "image/jpeg",
"size": len(result.content)
"size": len(result.content),
"w": capture.width,
"h": capture.height
}
}
else:
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
humanize
pika
pillow

1 comment on commit 0137e65

@turt2live
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually fixes #6

Please sign in to comment.