@@ -70,6 +70,7 @@ def create_from_path(cls, path, dataset_id=None):
7070 image .path = path
7171 image .width = pil_image .size [0 ]
7272 image .height = pil_image .size [1 ]
73+ image .regenerate_thumbnail = True
7374
7475 if dataset_id is not None :
7576 image .dataset_id = dataset_id
@@ -94,15 +95,12 @@ def delete(self, *args, **kwargs):
9495
9596 def thumbnail (self ):
9697 """
97- Generates (if required) and returns thumbnail
98+ Generates (if required) thumbnail
9899 """
99100
100101 thumbnail_path = self .thumbnail_path ()
101102
102- if self .regenerate_thumbnail or \
103- not os .path .isfile (thumbnail_path ):
104-
105- # logger.debug(f'Generating thumbnail for {self.id}')
103+ if self .regenerate_thumbnail :
106104
107105 pil_image = self .generate_thumbnail ()
108106 pil_image = pil_image .convert ("RGB" )
@@ -116,9 +114,14 @@ def thumbnail(self):
116114
117115 self .update (is_modified = False )
118116 return pil_image
119- else :
120- return Image .open (thumbnail_path )
121-
117+
118+ def open_thumbnail (self ):
119+ """
120+ Return thumbnail
121+ """
122+ thumbnail_path = self .thumbnail_path ()
123+ return Image .open (thumbnail_path )
124+
122125 def thumbnail_path (self ):
123126 folders = self .path .split ('/' )
124127 folders .insert (len (folders )- 1 , self .THUMBNAIL_DIRECTORY )
0 commit comments