Skip to content

Commit

Permalink
now saving normalized artist image and thumbnail
Browse files Browse the repository at this point in the history
  • Loading branch information
thomiel committed Nov 22, 2018
1 parent 0795647 commit 47ccdf2
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
8 changes: 4 additions & 4 deletions collecting_society_portal_repertoire/templates/artist/list.pt
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@
<td class="cs-img-thumb">
<a href="${request.resource_path(
context, artist.code)}">
<img tal:condition="artist.picture_data"
tal:define="pic h.b64encode(artist.picture_data) | None"
<img tal:condition="artist.picture_thumbnail_data"
tal:define="pic h.b64encode(artist.picture_thumbnail_data) | None"
class="img-responsive center-block"
src="data:${artist.picture_data_mime_type};base64,${pic}" />
<img tal:condition="not artist.picture_data and not artist.group"
<img tal:condition="not artist.picture_thumbnail_data and not artist.group"
class="img-responsive center-block"
src="${request.static_path(
'collecting_society_portal_repertoire:'
'static/img/element-icon-soloartists-green.png')}" />
<img tal:condition="not artist.picture_data and artist.group"
<img tal:condition="not artist.picture_thumbnail_data and artist.group"
class="img-responsive center-block"
src="${request.static_path(
'collecting_society_portal_repertoire:'
Expand Down
33 changes: 27 additions & 6 deletions collecting_society_portal_repertoire/views/forms/edit_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import logging
import deform

from PIL import Image
from PIL import ImageFile
import io

from collecting_society_portal.models import (
Tdb,
Party,
Expand Down Expand Up @@ -99,12 +103,29 @@ def update_artist(self):

# picture
if self.appstruct['picture']:
with open(self.appstruct['picture']['fp'].name,
mode='rb') as picfile:
picture_data = picfile.read()
mimetype = self.appstruct['picture']['mimetype']
artist.picture_data = picture_data
artist.picture_data_mime_type = mimetype
# with open(self.appstruct['picture']['fp'].name,
# mode='rb') as picfile:
# picture_data = picfile.read()

#import rpdb2; rpdb2.start_embedded_debugger("supersecret", fAllowRemote = True)
#ImageFile.LOAD_TRUNCATED_IMAGES = True
try:
image = Image.open(self.appstruct['picture']['fp'].name)
thumb = image.copy()
thumb.thumbnail((84, 84), Image.ANTIALIAS)
image.thumbnail((509, 509), Image.ANTIALIAS)
with io.BytesIO() as picture_thumbnail_data:
thumb.save(picture_thumbnail_data, "JPEG")
picture_thumbnail_data.seek(0)
artist.picture_thumbnail_data = picture_thumbnail_data.read()
with io.BytesIO() as picture_data:
image.save(picture_data, "JPEG")
picture_data.seek(0)
artist.picture_data = picture_data.read()
# mimetype = self.appstruct['picture']['mimetype']
artist.picture_data_mime_type = 'image/jpeg' # mimetype
except IOError as e:
log.debug('Error while processing picture data: %s', e)

# members
if artist.group:
Expand Down

0 comments on commit 47ccdf2

Please sign in to comment.