Merge remote branch 'remotes/jwandborg/feature_400-resize_images_to_fit_page'
Conflicts: mediagoblin/templates/mediagoblin/user_pages/media.html
This commit is contained in:
commit
d8db3f112e
@ -22,6 +22,7 @@ from mediagoblin import mg_globals as mgg
|
|||||||
|
|
||||||
|
|
||||||
THUMB_SIZE = 200, 200
|
THUMB_SIZE = 200, 200
|
||||||
|
MEDIUM_SIZE = 640, 640
|
||||||
|
|
||||||
|
|
||||||
def create_pub_filepath(entry, filename):
|
def create_pub_filepath(entry, filename):
|
||||||
@ -43,10 +44,7 @@ def process_media_initial(media_id):
|
|||||||
mgg.queue_store, queued_filepath,
|
mgg.queue_store, queued_filepath,
|
||||||
'source')
|
'source')
|
||||||
|
|
||||||
queued_file = file(queued_filename, 'r')
|
thumb = Image.open(queued_filename)
|
||||||
|
|
||||||
with queued_file:
|
|
||||||
thumb = Image.open(queued_file)
|
|
||||||
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
|
thumb.thumbnail(THUMB_SIZE, Image.ANTIALIAS)
|
||||||
# ensure color mode is compatible with jpg
|
# ensure color mode is compatible with jpg
|
||||||
if thumb.mode != "RGB":
|
if thumb.mode != "RGB":
|
||||||
@ -58,6 +56,21 @@ def process_media_initial(media_id):
|
|||||||
with thumb_file:
|
with thumb_file:
|
||||||
thumb.save(thumb_file, "JPEG")
|
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")
|
||||||
|
|
||||||
|
medium_filepath = create_pub_filepath(entry, 'medium.jpg')
|
||||||
|
|
||||||
|
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
|
# we have to re-read because unlike PIL, not everything reads
|
||||||
# things in string representation :)
|
# things in string representation :)
|
||||||
queued_file = file(queued_filename, 'rb')
|
queued_file = file(queued_filename, 'rb')
|
||||||
@ -73,6 +86,7 @@ def process_media_initial(media_id):
|
|||||||
media_files_dict = entry.setdefault('media_files', {})
|
media_files_dict = entry.setdefault('media_files', {})
|
||||||
media_files_dict['thumb'] = thumb_filepath
|
media_files_dict['thumb'] = thumb_filepath
|
||||||
media_files_dict['main'] = main_filepath
|
media_files_dict['main'] = main_filepath
|
||||||
|
media_files_dict['medium'] = medium_filepath
|
||||||
entry['state'] = u'processed'
|
entry['state'] = u'processed'
|
||||||
entry.save()
|
entry.save()
|
||||||
|
|
||||||
|
@ -22,8 +22,14 @@
|
|||||||
{% block mediagoblin_content %}
|
{% block mediagoblin_content %}
|
||||||
{% if media %}
|
{% if media %}
|
||||||
<div class="grid_8 alpha media_image">
|
<div class="grid_8 alpha media_image">
|
||||||
<img src="{{ request.app.public_store.file_url(
|
{% 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) }}" />
|
media.media_files.main) }}" />
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<h2>
|
<h2>
|
||||||
{{media.title}}
|
{{media.title}}
|
||||||
</h2>
|
</h2>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user