from rawpy import imread import imageio from rawpy._rawpy import LibRawNoThumbnailError, LibRawUnsupportedThumbnailError, ThumbFormat def extract_jpg_thumb(raw_file_path): with imread(raw_file_path) as raw: try: thumb = raw.extract_thumb() except (LibRawNoThumbnailError, LibRawUnsupportedThumbnailError): return None if thumb.format == ThumbFormat.JPEG: with open('thumbnail.jpg', 'wb') as f: f.write(thumb.data) elif thumb.format == ThumbFormat.BITMAP: imageio.imsave('thumbnail.jpg', thumb.data) else: return None return 'thumbnail.jpg' # thumbnail_path = extract_jpg_thumb('your_raw_image.nef') # if thumbnail_path: # print("Thumbnail extracted to:", thumbnail_path) # else: # print("No thumbnail found or unsupported format.")