mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-10 16:22:22 +03:00
Removed CONVERT helper variables
This commit is contained in:
parent
bb88d8d017
commit
35943372f0
|
@ -257,16 +257,22 @@ def netpbm_available():
|
||||||
return bool(shutil.which("ppmquant") and shutil.which("ppmtogif"))
|
return bool(shutil.which("ppmquant") and shutil.which("ppmtogif"))
|
||||||
|
|
||||||
|
|
||||||
def convert_available():
|
def magick_command():
|
||||||
return imagemagick_available() or graphicsmagick_available()
|
if sys.platform == "win32":
|
||||||
|
imagemagick = os.environ.get("MAGICK_HOME", "")
|
||||||
|
if imagemagick:
|
||||||
|
imagemagick = [os.path.join(imagemagick, "convert.exe")]
|
||||||
|
graphicsmagick = [os.path.join(imagemagick, "gm.exe"), "convert"]
|
||||||
|
else:
|
||||||
|
graphicsmagick = None
|
||||||
|
else:
|
||||||
|
imagemagick = ["convert"]
|
||||||
|
graphicsmagick = ["gm", "convert"]
|
||||||
|
|
||||||
|
if imagemagick and shutil.which(imagemagick[0]):
|
||||||
def imagemagick_available():
|
return imagemagick
|
||||||
return bool(IMCONVERT and shutil.which(IMCONVERT[0]))
|
elif graphicsmagick and shutil.which(graphicsmagick[0]):
|
||||||
|
return graphicsmagick
|
||||||
|
|
||||||
def graphicsmagick_available():
|
|
||||||
return bool(GMCONVERT and shutil.which(GMCONVERT[0]))
|
|
||||||
|
|
||||||
|
|
||||||
def on_appveyor():
|
def on_appveyor():
|
||||||
|
@ -304,24 +310,6 @@ def is_mingw():
|
||||||
return sysconfig.get_platform() == "mingw"
|
return sysconfig.get_platform() == "mingw"
|
||||||
|
|
||||||
|
|
||||||
if sys.platform == "win32":
|
|
||||||
IMCONVERT = os.environ.get("MAGICK_HOME", "")
|
|
||||||
GMCONVERT = None
|
|
||||||
if IMCONVERT:
|
|
||||||
IMCONVERT = [os.path.join(IMCONVERT, "convert.exe")]
|
|
||||||
GMCONVERT = [os.path.join(IMCONVERT, "gm.exe"), "convert"]
|
|
||||||
else:
|
|
||||||
IMCONVERT = ["convert"]
|
|
||||||
GMCONVERT = ["gm", "convert"]
|
|
||||||
|
|
||||||
if imagemagick_available():
|
|
||||||
CONVERT = IMCONVERT
|
|
||||||
elif graphicsmagick_available():
|
|
||||||
CONVERT = GMCONVERT
|
|
||||||
else:
|
|
||||||
CONVERT = None
|
|
||||||
|
|
||||||
|
|
||||||
class cached_property:
|
class cached_property:
|
||||||
def __init__(self, func):
|
def __init__(self, func):
|
||||||
self.func = func
|
self.func = func
|
||||||
|
|
|
@ -5,9 +5,7 @@ import pytest
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from .helper import CONVERT, assert_image_equal, convert_available, hopper
|
from .helper import assert_image_equal, hopper, magick_command
|
||||||
|
|
||||||
_roundtrip = convert_available()
|
|
||||||
|
|
||||||
|
|
||||||
def helper_save_as_palm(tmp_path, mode):
|
def helper_save_as_palm(tmp_path, mode):
|
||||||
|
@ -23,13 +21,10 @@ def helper_save_as_palm(tmp_path, mode):
|
||||||
assert os.path.getsize(outfile) > 0
|
assert os.path.getsize(outfile) > 0
|
||||||
|
|
||||||
|
|
||||||
def open_with_convert(tmp_path, f):
|
def open_with_magick(magick, tmp_path, f):
|
||||||
if not convert_available():
|
|
||||||
raise OSError()
|
|
||||||
|
|
||||||
outfile = str(tmp_path / "temp.png")
|
outfile = str(tmp_path / "temp.png")
|
||||||
rc = subprocess.call(
|
rc = subprocess.call(
|
||||||
CONVERT + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
|
magick + [f, outfile], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT
|
||||||
)
|
)
|
||||||
if rc:
|
if rc:
|
||||||
raise OSError
|
raise OSError
|
||||||
|
@ -37,14 +32,15 @@ def open_with_convert(tmp_path, f):
|
||||||
|
|
||||||
|
|
||||||
def roundtrip(tmp_path, mode):
|
def roundtrip(tmp_path, mode):
|
||||||
if not _roundtrip:
|
magick = magick_command()
|
||||||
|
if not magick:
|
||||||
return
|
return
|
||||||
|
|
||||||
im = hopper(mode)
|
im = hopper(mode)
|
||||||
outfile = str(tmp_path / "temp.palm")
|
outfile = str(tmp_path / "temp.palm")
|
||||||
|
|
||||||
im.save(outfile)
|
im.save(outfile)
|
||||||
converted = open_with_convert(tmp_path, outfile)
|
converted = open_with_magick(magick, tmp_path, outfile)
|
||||||
assert_image_equal(converted, im)
|
assert_image_equal(converted, im)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user