

@property
def crop_thumb(self):
    from cropduster.models import Thumb
    try:
        pil_img = PIL.Image.open(self.file_path)
    except:
        return None
    (orig_w, orig_h) = pil_img.size
    dimensions = self.get('Regions', {
        
    }).get('AppliedToDimensions', None)
    if (not isinstance(dimensions, dict)):
        return None
    (w, h) = (dimensions.get('w'), dimensions.get('h'))
    if (not all(map((lambda v: isinstance(v, int)), [w, h]))):
        return None
    region_list = self.get('Regions', {
        
    }).get('RegionList', [])
    if (not isinstance(region_list, list)):
        return None
    try:
        crop_region = [r for r in region_list if (r['Name'] == 'Crop')][0]
    except IndexError:
        return None
    if ((not isinstance(crop_region, dict)) or (not isinstance(crop_region.get('Area'), dict))):
        return None
    area = crop_region.get('Area')
    if (not all([isinstance(v, float) for (k, v) in area.items() if (k in ('w', 'h', 'x', 'y'))])):
        return None
    return Thumb(name='crop', crop_x=(area['x'] * w), crop_y=(area['y'] * h), crop_w=(area['w'] * w), crop_h=(area['h'] * h), width=orig_w, height=orig_h)

dataset/ETHPy150Open theatlantic/django-cropduster/cropduster/standalone/metadata.py MetadataDict.crop_thumb/original