mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
Call init() if mimetype is not found with preinit()
This commit is contained in:
parent
b7585b0597
commit
f15d7265f7
|
@ -106,11 +106,10 @@ $ms = new-object System.IO.MemoryStream(, $bytes)
|
|||
),
|
||||
reason="Linux with wl-clipboard only",
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"image_path", ["Tests/images/hopper.gif", "Tests/images/hopper.png"]
|
||||
)
|
||||
def test_grabclipboard_wl_clipboard(self, image_path):
|
||||
with open(image_path, mode="rb") as raw_image:
|
||||
subprocess.call(["wl-copy"], stdin=raw_image)
|
||||
@pytest.mark.parametrize("ext", ("gif", "png", "ico"))
|
||||
def test_grabclipboard_wl_clipboard(self, ext):
|
||||
image_path = "Tests/images/hopper." + ext
|
||||
with open(image_path, "rb") as fp:
|
||||
subprocess.call(["wl-copy"], stdin=fp)
|
||||
im = ImageGrab.grabclipboard()
|
||||
assert_image_equal_tofile(im, image_path)
|
||||
|
|
|
@ -137,11 +137,19 @@ def grabclipboard():
|
|||
args = ["wl-paste"]
|
||||
output = subprocess.check_output(["wl-paste", "-l"]).decode()
|
||||
clipboard_mimetypes = output.splitlines()
|
||||
|
||||
def find_mimetype():
|
||||
for mime in Image.MIME.values():
|
||||
if mime in clipboard_mimetypes:
|
||||
return mime
|
||||
|
||||
Image.preinit()
|
||||
for mimetype in Image.MIME.values():
|
||||
if mimetype in clipboard_mimetypes:
|
||||
args.extend(["-t", mimetype])
|
||||
break
|
||||
mimetype = find_mimetype()
|
||||
if not mimetype:
|
||||
Image.init()
|
||||
mimetype = find_mimetype()
|
||||
if mimetype:
|
||||
args.extend(["-t", mimetype])
|
||||
elif shutil.which("xclip"):
|
||||
args = ["xclip", "-selection", "clipboard", "-t", "image/png", "-o"]
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue
Block a user