コード例 #1
0
 def get_thumbnail(self, size, original_file_source=False, file_mimeype=None):
     cache = CacheDriverFactory().get_cache('openslide')
     # get thumbnail from cache
     thumb = cache.thumbnail_from_cache(self.image_id, size,
                                        settings.DEEPZOOM_FORMAT)
     # if thumbnail is not in cache build it ....
     if thumb is None:
         self.logger.info('No thumbnail loaded from cache, building it')
         slide = self._get_openslide_wrapper(original_file_source, file_mimeype)
         if slide:
             thumb = slide.get_thumbnail((size, size))
             # ... and store it into the cache
             cache.thumbnail_to_cache(self.image_id, thumb, size,
                                      settings.DEEPZOOM_FORMAT)
     else:
         self.logger.info('Thumbnail loaded from cache')
     return thumb, settings.DEEPZOOM_FORMAT
コード例 #2
0
ファイル: ome_engine.py プロジェクト: crs4/ome_seadragon
 def get_thumbnail(self, size, original_file_source=False, file_mimeype=None):
     self._check_source_type(original_file_source)
     cache = CacheDriverFactory().get_cache('omero')
     thumbnail = cache.thumbnail_from_cache(self.image_id, size,
                                            settings.DEEPZOOM_FORMAT)
     if thumbnail is None:
         self.logger.info('No thumbnail loaded from cache, building it')
         # we want the thumbnail of the image, not the one of the highest resolution image in fileset
         ome_img = self._get_image_object(get_biggest_in_fileset=False)
         if ome_img:
             if ome_img.getSizeX() >= ome_img.getSizeY():
                 th_size = (size, )
             else:
                 th_w = size * (float(ome_img.getSizeX()) / ome_img.getSizeY())
                 th_size = (th_w, size)
             thumbnail_buffer = StringIO(ome_img.getThumbnail(size=th_size))
             thumbnail = Image.open(thumbnail_buffer)
             cache.thumbnail_to_cache(self.image_id, thumbnail, size,
                                      settings.DEEPZOOM_FORMAT)
     else:
         self.logger.info('Thumbnail loaded from cache')
     return thumbnail, settings.DEEPZOOM_FORMAT