Loading imgutils/data/blob.py +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ def load_image_from_blob_url(blob_url: str) -> Image.Image: >>> img = load_image_from_blob_url(blob_url) >>> img.show() """ header, data = blob_url.split(",", 1) header, data = blob_url.split(",", maxsplit=1) meta_parts = header.split(";") mimetype = meta_parts[0][5:] encoding = meta_parts[1] if len(meta_parts) > 1 else "" Loading test/data/test_blob.py +31 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,37 @@ class TestDataBlob: with pytest.raises(ValueError): load_image_from_blob_url('data:image/webp;xxxxxx,abcde12345') @pytest.mark.parametrize(*tmatrix({ 'filename': [ 'mostima_post.jpg', 'soldiers.jpg', 'nian.png', ], ('format', 'mimetype'): [ ('jpg', 'image/jpeg'), ('jpeg', 'image/jpeg'), ('png', 'image/png'), ('webp', 'image/webp'), ], 'rp_mimetype': [ 'image/jpeg', 'image/png', 'image/webp', '', ] }, mode='matrix')) def test_to_blob_url_format_check_mimetype(self, filename, format, mimetype, rp_mimetype, image_diff): original_image = load_image(get_testfile(filename), mode='RGB', force_background='white') blob_url = to_blob_url(original_image, format=format) assert blob_url.startswith(f'data:{mimetype};base64,') blob_url = blob_url.replace(f'data:{mimetype};', f'data:{rp_mimetype};') with pytest.warns(UserWarning if mimetype != rp_mimetype else None): assert image_diff( original_image, load_image_from_blob_url(blob_url), throw_exception=False, ) < 1.5e-2 @pytest.mark.parametrize(['blob_url', 'expected_result'], [ ("data:image/png;base64,ABC", True), ("DATA:IMAGE/JPEG,", True), Loading Loading
imgutils/data/blob.py +1 −1 Original line number Diff line number Diff line Loading @@ -71,7 +71,7 @@ def load_image_from_blob_url(blob_url: str) -> Image.Image: >>> img = load_image_from_blob_url(blob_url) >>> img.show() """ header, data = blob_url.split(",", 1) header, data = blob_url.split(",", maxsplit=1) meta_parts = header.split(";") mimetype = meta_parts[0][5:] encoding = meta_parts[1] if len(meta_parts) > 1 else "" Loading
test/data/test_blob.py +31 −0 Original line number Diff line number Diff line Loading @@ -50,6 +50,37 @@ class TestDataBlob: with pytest.raises(ValueError): load_image_from_blob_url('data:image/webp;xxxxxx,abcde12345') @pytest.mark.parametrize(*tmatrix({ 'filename': [ 'mostima_post.jpg', 'soldiers.jpg', 'nian.png', ], ('format', 'mimetype'): [ ('jpg', 'image/jpeg'), ('jpeg', 'image/jpeg'), ('png', 'image/png'), ('webp', 'image/webp'), ], 'rp_mimetype': [ 'image/jpeg', 'image/png', 'image/webp', '', ] }, mode='matrix')) def test_to_blob_url_format_check_mimetype(self, filename, format, mimetype, rp_mimetype, image_diff): original_image = load_image(get_testfile(filename), mode='RGB', force_background='white') blob_url = to_blob_url(original_image, format=format) assert blob_url.startswith(f'data:{mimetype};base64,') blob_url = blob_url.replace(f'data:{mimetype};', f'data:{rp_mimetype};') with pytest.warns(UserWarning if mimetype != rp_mimetype else None): assert image_diff( original_image, load_image_from_blob_url(blob_url), throw_exception=False, ) < 1.5e-2 @pytest.mark.parametrize(['blob_url', 'expected_result'], [ ("data:image/png;base64,ABC", True), ("DATA:IMAGE/JPEG,", True), Loading