Skip to content

Commit

Permalink
Respect MAGICK_HOME on Windows
Browse files Browse the repository at this point in the history
 - Don't read Windows registry if MAGICK_HOME was set, keep the original value
   of the environment variable.
 - It now seems to be enough to only add the path to the main DLL to PATH.
   This is also what the ImageMagick installer does if you ask it to add
   ImageMagick to PATH.
  • Loading branch information
Roeland Schoukens committed Sep 26, 2024
1 parent ae258eb commit 1965b74
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions wand/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,17 @@ def library_paths():
magick_home = os.environ.get('MAGICK_HOME')
magick_suffix = os.environ.get('WAND_MAGICK_LIBRARY_SUFFIX')

if system == 'Windows':
# ImageMagick installers normally install coder and filter DLLs in
# subfolders, we need to add those folders to PATH, otherwise loading
# the DLL later will fail.
if system == 'Windows' and magick_home is None:
try:
# Try to read ImageMagick location from registry.
# This is necessary if the user did not add the ImageMagick directory
# to PATH.
with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
r"SOFTWARE\ImageMagick\Current") as reg_key:
libPath = winreg.QueryValueEx(reg_key, "LibPath")
coderPath = winreg.QueryValueEx(reg_key, "CoderModulesPath")
filterPath = winreg.QueryValueEx(reg_key, "FilterModulesPath")
magick_home = libPath[0]
os.environ['PATH'] += str((';' + libPath[0] + ";" +
coderPath[0] + ";" + filterPath[0]))
os.environ['PATH'] += ';' + str(magick_home)
except OSError:
# otherwise use MAGICK_HOME, and we assume the coder and
# filter DLLs are in the same directory
pass

def magick_path(path):
Expand Down

0 comments on commit 1965b74

Please sign in to comment.