Skip to content

Commit c7f0f88

Browse files
committed
rename get_thumbnail_path -> get_cropped_path
1 parent 55e1644 commit c7f0f88

File tree

3 files changed

+3
-68
lines changed

3 files changed

+3
-68
lines changed

finder/contrib/image/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Meta:
2929
def summary(self):
3030
return "{width}×{height}px ({size})".format(size=super().summary, width=self.width, height=self.height)
3131

32-
def get_thumbnail_path(self, width, height):
32+
def get_cropped_path(self, width, height):
3333
id = str(self.id)
3434
thumbnail_folder = self.filer_public_thumbnails / f'{id[0:2]}/{id[2:4]}/{id}'
3535
thumbnail_path = Path(self.file_name)

finder/contrib/image/pil/models.py

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def save(self, **kwargs):
5454
super().save(**kwargs)
5555

5656
def get_thumbnail_url(self):
57-
thumbnail_path = self.get_thumbnail_path(self.thumbnail_size, self.thumbnail_size)
57+
thumbnail_path = self.get_cropped_path(self.thumbnail_size, self.thumbnail_size)
5858
if not default_storage.exists(thumbnail_path):
5959
try:
6060
self.crop(thumbnail_path, self.thumbnail_size, self.thumbnail_size)
@@ -168,68 +168,3 @@ def crop(self, thumbnail_path, width, height):
168168
(default_storage.base_location / thumbnail_path.parent).mkdir(parents=True, exist_ok=True)
169169
image.save(default_storage.open(thumbnail_path, 'wb'), image.format)
170170
return image
171-
172-
def crop_centered(self, image):
173-
width, height = image.size
174-
if width > height:
175-
min_x = (width - height) / 2
176-
min_y = 0
177-
max_x = (width + height) / 2
178-
max_y = height
179-
else:
180-
min_x = 0
181-
min_y = (height - width) / 2
182-
max_x = width
183-
max_y = (height + width) / 2
184-
return image.crop((min_x, min_y, max_x, max_y))
185-
186-
def crop_eccentric(self, image, crop_x, crop_y, crop_size, gravity):
187-
"""
188-
with cropping, the expected resizing could be done using:
189-
`image = image.crop((crop_x, crop_y, crop_x + crop_size, crop_y + crop_size))`
190-
however, for small selections or images in low resolution this might result
191-
in blurry preview images. We therefore want to use at least `thumbnail_size`
192-
pixels from the original image
193-
"""
194-
min_size = max(crop_size, self.thumbnail_size)
195-
off_size = min_size - crop_size
196-
197-
# horizontal thumbnailing
198-
if gravity in ('e', 'ne', 'se'):
199-
max_x = min(crop_x + min_size, image.width)
200-
min_x = max(max_x - min_size, 0)
201-
elif gravity in ('w', 'nw', 'sw'):
202-
min_x = max(crop_x - off_size, 0)
203-
else:
204-
min_x = max(crop_x - off_size / 2, 0)
205-
if min_x + min_size > image.width:
206-
min_x = max(image.width - min_size, 0)
207-
max_x = image.width
208-
else:
209-
max_x = min_x + min_size
210-
211-
# vertical thumbnailing
212-
if gravity in ('s', 'se', 'sw'):
213-
max_y = min(crop_y + min_size, image.height)
214-
min_y = max(max_y - min_size, 0)
215-
elif gravity in ('n', 'ne', 'nw'):
216-
min_y = max(crop_y - off_size, 0)
217-
else:
218-
min_y = max(crop_y - off_size / 2, 0)
219-
if min_y + min_size > image.height:
220-
min_y = max(image.height - min_size, 0)
221-
max_y = image.height
222-
else:
223-
max_y = min_y + min_size
224-
225-
# correct thumbnailing for low resolution images with an aspect ratio unequal to 1
226-
if round(max_x - min_x) > round(max_y - min_y):
227-
off_size = (max_x - min_x - max_y + min_y) / 2
228-
min_x += off_size
229-
max_x -= off_size
230-
elif round(max_x - min_x) < round(max_y - min_y):
231-
off_size = (max_y - min_y - max_x + min_x) / 2
232-
min_y += off_size
233-
max_y -= off_size
234-
235-
return image.crop((min_x, min_y, max_x, max_y))

finder/contrib/image/svg/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def save(self, **kwargs):
4141
super().save(**kwargs)
4242

4343
def get_thumbnail_url(self):
44-
thumbnail_path = self.get_thumbnail_path(self.thumbnail_size, self.thumbnail_size)
44+
thumbnail_path = self.get_cropped_path(self.thumbnail_size, self.thumbnail_size)
4545
if not default_storage.exists(thumbnail_path):
4646
drawing = svg2rlg(default_storage.path(self.file_path))
4747
if not drawing:

0 commit comments

Comments
 (0)