def _path_info_dict(self, storage_path): try: with default_storage.open(storage_path, 'rb') as im_file: width, height = get_image_dimensions(im_file) except IOERRORS: return AdjustmentInfoDict() if self.calc_uses_areas: areas = self.get_areas(storage_path) else: areas = None for adjustment in self.adjustments: width, height = adjustment.calculate((width, height), areas=areas) url = u"{0}?{1}".format( reverse('daguerre_adjusted_image_redirect', kwargs={'storage_path': storage_path}), self.to_querydict(secure=True).urlencode() ) ajax_url = u"{0}?{1}".format( reverse('daguerre_ajax_adjustment_info', kwargs={'storage_path': storage_path}), self.to_querydict(secure=False).urlencode() ) return AdjustmentInfoDict({ 'width': width, 'height': height, 'url': url, 'ajax_url': ajax_url, })
def _path_info_dict(self, storage_path): try: with default_storage.open(storage_path, 'rb') as im_file: width, height = get_image_dimensions(im_file) except IOERRORS + (TypeError,): # TypeError will be raised if for any reason storage_path's # dimensions can't be determined. get_image_dimensions will # return None, which can't be split into width and height. return AdjustmentInfoDict() if self.calc_uses_areas: areas = self.get_areas(storage_path) else: areas = None for adjustment in self.adjustments: width, height = adjustment.calculate((width, height), areas=areas) url = u"{0}?{1}".format( reverse('daguerre_adjusted_image_redirect', kwargs={'storage_path': storage_path}), self.to_querydict(secure=True).urlencode() ) ajax_url = u"{0}?{1}".format( reverse('daguerre_ajax_adjustment_info', kwargs={'storage_path': storage_path}), self.to_querydict(secure=False).urlencode() ) return AdjustmentInfoDict({ 'width': width, 'height': height, 'url': url, 'ajax_url': ajax_url, })
def test_non_exif(self): dim = get_image_dimensions(self._data_path('20x7_no_exif.png')) self.assertEqual(dim, self.ORIGINAL_ORIENTATION)
def test_exif_not_rotated(self): dim = get_image_dimensions(self._data_path('20x7_exif_not_rotated.jpg')) self.assertEqual(dim, self.ORIGINAL_ORIENTATION)
def test_exif_not_rotated(self): dim = get_image_dimensions( self._data_path('20x7_exif_not_rotated.jpg')) self.assertEqual(dim, self.ORIGINAL_ORIENTATION)