1616
1717
1818import collections
19- import imghdr
2019import json
2120
2221from werkzeug import wrappers
3029from tensorboard .plugins .image import metadata as image_metadata
3130from tensorboard .plugins .metrics import metadata
3231from tensorboard .plugins .scalar import metadata as scalar_metadata
32+ from tensorboard .util import img_mime_type_detector
3333
3434
35- _IMGHDR_TO_MIMETYPE = {
36- "bmp" : "image/bmp" ,
37- "gif" : "image/gif" ,
38- "jpeg" : "image/jpeg" ,
39- "png" : "image/png" ,
40- "svg" : "image/svg+xml" ,
41- }
42-
43- _DEFAULT_IMAGE_MIMETYPE = "application/octet-stream"
44-
4535_SINGLE_RUN_PLUGINS = frozenset (
4636 [histogram_metadata .PLUGIN_NAME , image_metadata .PLUGIN_NAME ]
4737)
@@ -615,8 +605,8 @@ def _serve_image_data(self, request):
615605 if not blob_key :
616606 raise errors .InvalidArgumentError ("Missing 'imageId' field" )
617607
618- (data , content_type ) = self ._image_data_impl (ctx , blob_key )
619- return http_util .Respond (request , data , content_type )
608+ (data , mime_type ) = self ._image_data_impl (ctx , blob_key )
609+ return http_util .Respond (request , data , mime_type )
620610
621611 def _image_data_impl (self , ctx , blob_key ):
622612 """Gets the image data for a blob key.
@@ -631,8 +621,5 @@ def _image_data_impl(self, ctx, blob_key):
631621 content_type: a string HTTP content type.
632622 """
633623 data = self ._data_provider .read_blob (ctx , blob_key = blob_key )
634- image_type = imghdr .what (None , data )
635- content_type = _IMGHDR_TO_MIMETYPE .get (
636- image_type , _DEFAULT_IMAGE_MIMETYPE
637- )
638- return (data , content_type )
624+ mime_type = img_mime_type_detector .from_bytes (data )
625+ return (data , mime_type )
0 commit comments