Now trying to hook up numpy and pillow to get image info and enable resizing
This commit is contained in:
parent
2e2bd9df4c
commit
27ce04756a
2
setup.py
2
setup.py
@ -14,6 +14,8 @@ requires = [
|
||||
'transaction',
|
||||
'zope.sqlalchemy',
|
||||
'SQLAlchemy',
|
||||
'pillow',
|
||||
'numpy'
|
||||
]
|
||||
|
||||
setup(name='Soter',
|
||||
|
@ -101,6 +101,7 @@ class Picture(Base):
|
||||
album_id = Column('album_id', GUID(), ForeignKey('albums.id'), nullable=False)
|
||||
is_public = Column('is_public', Boolean, nullable=False)
|
||||
|
||||
tags = relationship("Tag", secondary=picture_tag)
|
||||
user = relationship('User', primaryjoin="User.id==Picture.user_id", cascade=None)
|
||||
|
||||
def __init__(self, name, url, user_id, album_id, is_public, id=None, is_fixture=False):
|
||||
|
@ -2,14 +2,14 @@ import os
|
||||
import shutil
|
||||
import uuid
|
||||
|
||||
from PIL import Image, ExifTags
|
||||
import pkg_resources
|
||||
from pyramid.response import FileResponse
|
||||
|
||||
from pyramid.security import authenticated_userid
|
||||
|
||||
from pyramid.view import view_config
|
||||
import transaction
|
||||
|
||||
import numpy
|
||||
from soter.models import DBSession
|
||||
from soter.models.master import Picture
|
||||
|
||||
@ -32,12 +32,33 @@ def upload(request):
|
||||
with open(temp_file_path, 'wb') as output_file:
|
||||
shutil.copyfileobj(input_file, output_file)
|
||||
os.rename(temp_file_path, file_path)
|
||||
# Process picture here to get the hash and the exif tags to be added to the database
|
||||
pic = Picture(file_id, str(file_id), uuid.UUID(authenticated_userid(request)), uuid.UUID(album), True, file_id)
|
||||
DBSession.add(pic)
|
||||
transaction.commit()
|
||||
return {'location': file_path}
|
||||
|
||||
|
||||
def process_picture(path):
|
||||
image = get_image(path)
|
||||
Picture(file_id, str(file_id), uuid.UUID(authenticated_userid(request)), uuid.UUID(album), True, file_id)
|
||||
|
||||
|
||||
def get_image(path):
|
||||
image = Image.open(path)
|
||||
orientation = [tag for tag in ExifTags.TAGS.keys() if ExifTags.TAGS[tag] == 'Orientation'][0]
|
||||
exif = dict(image._getexif().items())
|
||||
if exif[orientation] == 3:
|
||||
image = image.rotate(180, expand=True)
|
||||
elif exif[orientation] == 6:
|
||||
image = image.rotate(270, expand=True)
|
||||
elif exif[orientation] == 8:
|
||||
image = image.rotate(90, expand=True)
|
||||
img = numpy.array(image)
|
||||
# CONVERT RGB TO BGR
|
||||
return img[:, :, ::-1].copy()
|
||||
|
||||
|
||||
@view_config(request_method='GET', route_name='picture_raw', permission='Albums')
|
||||
def show_raw(request):
|
||||
package, resource = ('soter:upload/' + request.matchdict['id'] + '.jpg').split(':', 1)
|
||||
|
Loading…
Reference in New Issue
Block a user