Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converts tiff and psd photo submissions to jpeg #404

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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