Skip to content

Commit

Permalink
Add screenshot resizer for support case attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
Pasha Radchenko committed Apr 13, 2021
1 parent 6a5cbf4 commit fd1b196
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
16 changes: 13 additions & 3 deletions autopsy_app/funcs.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import re
import string
import random
from flask import url_for
from autopsy_app import app, flask_bcrypt
from autopsy_app.model import Mortem, User
from io import BytesIO
from PIL import Image
from autopsy_app import flask_bcrypt
from autopsy_app.model import Mortem


def define_mortem_url():
Expand All @@ -29,5 +30,14 @@ def auto_tag(content):
m = tag_pattern.findall(content)
return [tag.lower() for tag in m]


def get_tags(tags_data):
return tags_data.strip("{}").split(",")


def resize_screenshot(scr):
img_byte_arr = BytesIO()
img = Image.open(scr)
img.resize((800, 600))
img.save(img_byte_arr, format='PNG')
return img_byte_arr.getvalue()
6 changes: 3 additions & 3 deletions autopsy_app/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from autopsy_app.mail import send_email, send_admin_email
from autopsy_app.funcs import (define_mortem_url, choose_random_mortem,
auto_tag, generate_password,
verify_password, get_tags)
verify_password, get_tags, resize_screenshot)


@app.route('/')
Expand Down Expand Up @@ -245,7 +245,7 @@ def support():
content = form.content.data
attach = form.attach.data
if attach:
attach_data = attach.read()
attach_data = resize_screenshot(attach.stream)
else:
attach_data = b''
now = datetime.datetime.utcnow()
Expand All @@ -255,7 +255,7 @@ def support():
support_created=now,
support_attach=attach_data,
user_id=uid)
send_admin_email(db, support_case)
# send_admin_email(db, support_case)
db.session.add(support_case)
db.session.commit()
flash('The Support Case has been created', 'warning')
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ itsdangerous==1.1.0
Jinja2==2.11.3
Mako==1.1.4
MarkupSafe==1.1.1
Pillow==8.2.0
psycopg2==2.8.6
pycparser==2.20
python-dateutil==2.8.1
Expand Down

0 comments on commit fd1b196

Please sign in to comment.