Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
converts tiff and psd submissions to jpeg
  • Loading branch information
ssempervirens committed Mar 19, 2018
1 parent b7f5df7 commit 5ea28b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions OpenOversight/app/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class BaseConfig(object):
# Upload Settings
MAX_CONTENT_LENGTH = 50 * 1024 * 1024
ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])
REQUIRES_CONV = set(['tiff', 'psd'])

SEED = 666

Expand Down
8 changes: 6 additions & 2 deletions OpenOversight/app/main/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,11 +448,15 @@ def submit_department_images(department_id=1):
@limiter.limit('250/minute')
def upload(department_id):
file_to_upload = request.files['file']
if not allowed_file(file_to_upload.filename):
if not allowed_file(file_to_upload.filename, 'ALLOWED_EXTENSIONS'):
return jsonify(error="File type not allowed!"), 415
original_filename = secure_filename(file_to_upload.filename)
image_data = file_to_upload.read()

if allowed_file (file_to_upload.filename, 'REQUIRES_CONV'):
changeimage = Image.open(file_to_upload.filename)
basename = os.path.splitext(file_to_upload.filename)[0].split('.')
changeimage.save(basename + '.jpeg')
os.remove(file_to_upload.filename)
# See if there is a matching photo already in the db
hash_img = compute_hash(image_data)
hash_found = Image.query.filter_by(hash_img=hash_img).first()
Expand Down
5 changes: 3 additions & 2 deletions OpenOversight/app/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import hashlib
import random
from PIL import Image
from sqlalchemy import func
from sqlalchemy.sql.expression import cast
import imghdr as imghdr
Expand Down Expand Up @@ -90,9 +91,9 @@ def edit_officer_profile(officer, form):
return officer


def allowed_file(filename):
def allowed_file(filename, extensions):
return '.' in filename and \
filename.rsplit('.', 1)[1].lower() in current_app.config['ALLOWED_EXTENSIONS']
filename.rsplit('.', 1)[1].lower() in current_app.config[extensions]


def get_random_image(image_query):
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ sqlalchemy==1.1.15
flask-sqlalchemy>=2.1
flask-bootstrap
gunicorn==17.5
Pillow
fabric
itsdangerous

0 comments on commit 5ea28b1

Please sign in to comment.