+ def cut_percentages(self):
+ img = PILImage.open(self.file)
+ max_w, max_h = 600, 600
+ w, h = img.size
+ scale = min(max_w / w, max_h / h)
+ ws, hs = round(w * scale), round(h * scale)
+
+ return {
+ 'left': 100 * self.cut_left / w,
+ 'right': 100 * self.cut_right / w,
+ 'top': 100 * self.cut_top / h,
+ 'bottom': 100 * self.cut_bottom / h,
+ 'width': ws,
+ 'height': hs,
+ 'th': f'{ws}x{hs}',
+ }
+
+ @property
+ def etag(self):
+ return f'{self.cut_top}.{self.cut_bottom}.{self.cut_left}.{self.cut_right}'
+
+ @property
+ def attribution(self):
+ pieces = []
+ if self.title:
+ pieces.append(self.title)
+ if self.author:
+ pieces.append(self.author)
+ if self.license_name:
+ pieces.append(self.license_name)
+ if self.source_url:
+ pieces.append(self.source_url.split('/')[2])
+ return ', '.join(pieces)
+
+