Merge remote-tracking branch 'remotes/slikdigit/bassam'
Conflicts: mediagoblin/media_types/image/processing.py
This commit is contained in:
commit
c051615889
@ -21,7 +21,8 @@ from mediagoblin import mg_globals as mgg
|
|||||||
from mediagoblin.processing import BadMediaFail, \
|
from mediagoblin.processing import BadMediaFail, \
|
||||||
create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE, FilenameBuilder
|
create_pub_filepath, THUMB_SIZE, MEDIUM_SIZE, FilenameBuilder
|
||||||
from mediagoblin.tools.exif import exif_fix_image_orientation, \
|
from mediagoblin.tools.exif import exif_fix_image_orientation, \
|
||||||
extract_exif, clean_exif, get_gps_data, get_useful
|
extract_exif, clean_exif, get_gps_data, get_useful, \
|
||||||
|
exif_image_needs_rotation
|
||||||
|
|
||||||
def resize_image(entry, filename, new_path, exif_tags, workdir, new_size,
|
def resize_image(entry, filename, new_path, exif_tags, workdir, new_size,
|
||||||
size_limits=(0, 0)):
|
size_limits=(0, 0)):
|
||||||
@ -62,7 +63,6 @@ def process_image(entry):
|
|||||||
conversions_subdir = os.path.join(
|
conversions_subdir = os.path.join(
|
||||||
workbench.dir, 'conversions')
|
workbench.dir, 'conversions')
|
||||||
os.mkdir(conversions_subdir)
|
os.mkdir(conversions_subdir)
|
||||||
|
|
||||||
queued_filepath = entry.queued_media_file
|
queued_filepath = entry.queued_media_file
|
||||||
queued_filename = workbench.localized_file(
|
queued_filename = workbench.localized_file(
|
||||||
mgg.queue_store, queued_filepath,
|
mgg.queue_store, queued_filepath,
|
||||||
@ -82,10 +82,16 @@ def process_image(entry):
|
|||||||
# If the size of the original file exceeds the specified size of a `medium`
|
# If the size of the original file exceeds the specified size of a `medium`
|
||||||
# file, a `.medium.jpg` files is created and later associated with the media
|
# file, a `.medium.jpg` files is created and later associated with the media
|
||||||
# entry.
|
# entry.
|
||||||
medium_filepath = create_pub_filepath(
|
medium = Image.open(queued_filename)
|
||||||
entry, name_builder.fill('{basename}.medium{ext}'))
|
if medium.size[0] > MEDIUM_SIZE[0] or medium.size[1] > MEDIUM_SIZE[1] \
|
||||||
resize_image(entry, queued_filename, medium_filepath,
|
or exif_image_needs_rotation(exif_tags):
|
||||||
exif_tags, conversions_subdir, MEDIUM_SIZE, MEDIUM_SIZE)
|
medium_filepath = create_pub_filepath(
|
||||||
|
entry, name_builder.fill('{basename}.medium{ext}'))
|
||||||
|
resize_image(
|
||||||
|
entry, queued_filename, medium_filepath,
|
||||||
|
exif_tags, conversions_subdir, MEDIUM_SIZE, MEDIUM_SIZE)
|
||||||
|
else:
|
||||||
|
medium_filepath = None
|
||||||
|
|
||||||
# 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 :)
|
||||||
@ -107,7 +113,8 @@ def process_image(entry):
|
|||||||
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['original'] = original_filepath
|
media_files_dict['original'] = original_filepath
|
||||||
media_files_dict['medium'] = medium_filepath
|
if medium_filepath:
|
||||||
|
media_files_dict['medium'] = medium_filepath
|
||||||
|
|
||||||
# Insert exif data into database
|
# Insert exif data into database
|
||||||
exif_all = clean_exif(exif_tags)
|
exif_all = clean_exif(exif_tags)
|
||||||
|
@ -32,6 +32,13 @@ USEFUL_TAGS = [
|
|||||||
'EXIF UserComment',
|
'EXIF UserComment',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def exif_image_needs_rotation(exif_tags):
|
||||||
|
"""
|
||||||
|
Returns True if EXIF orientation requires rotation
|
||||||
|
"""
|
||||||
|
return 'Image Orientation' in exif_tags \
|
||||||
|
and exif_tags['Image Orientation'].values[0] != 1
|
||||||
|
|
||||||
def exif_fix_image_orientation(im, exif_tags):
|
def exif_fix_image_orientation(im, exif_tags):
|
||||||
"""
|
"""
|
||||||
Translate any EXIF orientation to raw orientation
|
Translate any EXIF orientation to raw orientation
|
||||||
|
Loading…
x
Reference in New Issue
Block a user