@@ -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 ))
0 commit comments