THUMB_SIZE = 200, 200
+MEDIUM_SIZE = 640, 640
def create_pub_filepath(entry, filename):
mgg.queue_store, queued_filepath,
'source')
- queued_file = file(queued_filename, 'r')
+ thumb = Image.open(queued_filename)
+ thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
+ # ensure color mode is compatible with jpg
+ if thumb.mode != "RGB":
+ thumb = thumb.convert("RGB")
- with queued_file:
- thumb = Image.open(queued_file)
- thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
- # ensure color mode is compatible with jpg
- if thumb.mode != "RGB":
- thumb = thumb.convert("RGB")
+ thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
+
+ thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
+ with thumb_file:
+ thumb.save(thumb_file, "JPEG")
+
+ """
+ Create medium file, used in `media.html`
+ """
+ medium = Image.open(queued_filename)
+ medium.thumbnail(MEDIUM_SIZE, Image.ANTIALIAS)
+
+ if medium.mode != "RGB":
+ medium = medium.convert("RGB")
- thumb_filepath = create_pub_filepath(entry, 'thumbnail.jpg')
+ medium_filepath = create_pub_filepath(entry, 'medium.jpg')
- thumb_file = mgg.public_store.get_file(thumb_filepath, 'w')
- with thumb_file:
- thumb.save(thumb_file, "JPEG")
+ medium_file = mgg.public_store.get_file(medium_filepath, 'w')
+ with medium_file:
+ medium.save(medium_file, "JPEG")
# we have to re-read because unlike PIL, not everything reads
# things in string representation :)
media_files_dict = entry.setdefault('media_files', {})
media_files_dict['thumb'] = thumb_filepath
media_files_dict['main'] = main_filepath
+ media_files_dict['medium'] = medium_filepath
entry['state'] = u'processed'
entry.save()
<h1>
{{media.title}}
</h1>
- <img class="media_image" src="{{ request.app.public_store.file_url(
- media.media_files.main) }}" />
+ {% if media.media_files.medium %}
+ <img class="media_image" src="{{ request.app.public_store.file_url(
+ media.media_files.medium) }}" />
+ {% else %}
+ <img class="media_image" src="{{ request.app.public_store.file_url(
+ media.media_files.main) }}" />
+ {% endif %}
<p>
Uploaded on
{{ "%4d-%02d-%02d"|format(media.created.year,