···
1
+
diff --git a/wand/api.py b/wand/api.py
2
+
index 2c18513..1a1b511 100644
5
+
@@ -43,98 +43,6 @@ class c_magick_char_p(ctypes.c_char_p):
7
+
library.MagickRelinquishMemory(self)
10
+
-def library_paths():
11
+
- """Iterates for library paths to try loading. The result paths are not
12
+
- guaranteed that they exist.
14
+
- :returns: a pair of libwand and libmagick paths. they can be the same.
15
+
- path can be ``None`` as well
16
+
- :rtype: :class:`tuple`
21
+
- versions = '', '-6', '-Q16', '-Q8', '-6.Q16'
22
+
- options = '', 'HDRI', 'HDRI-2'
23
+
- system = platform.system()
24
+
- magick_home = os.environ.get('MAGICK_HOME')
26
+
- if system == 'Windows':
27
+
- # ImageMagick installers normally install coder and filter DLLs in
28
+
- # subfolders, we need to add those folders to PATH, otherwise loading
29
+
- # the DLL later will fail.
31
+
- with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE,
32
+
- r"SOFTWARE\ImageMagick\Current") as reg_key:
33
+
- libPath = winreg.QueryValueEx(reg_key, "LibPath")
34
+
- coderPath = winreg.QueryValueEx(reg_key, "CoderModulesPath")
35
+
- filterPath = winreg.QueryValueEx(reg_key, "FilterModulesPath")
36
+
- magick_home = libPath[0]
37
+
- os.environ['PATH'] += (';' + libPath[0] + ";" +
38
+
- coderPath[0] + ";" + filterPath[0])
40
+
- # otherwise use MAGICK_HOME, and we assume the coder and
41
+
- # filter DLLs are in the same directory
44
+
- def magick_path(path):
45
+
- return os.path.join(magick_home, *path)
46
+
- combinations = itertools.product(versions, options)
47
+
- for suffix in (version + option for version, option in combinations):
48
+
- # On Windows, the API is split between two libs. On other platforms,
49
+
- # it's all contained in one.
51
+
- if system == 'Windows':
52
+
- libwand = 'CORE_RL_wand_{0}.dll'.format(suffix),
53
+
- libmagick = 'CORE_RL_magick_{0}.dll'.format(suffix),
54
+
- yield magick_path(libwand), magick_path(libmagick)
55
+
- libwand = 'libMagickWand{0}.dll'.format(suffix),
56
+
- libmagick = 'libMagickCore{0}.dll'.format(suffix),
57
+
- yield magick_path(libwand), magick_path(libmagick)
58
+
- elif system == 'Darwin':
59
+
- libwand = 'lib', 'libMagickWand{0}.dylib'.format(suffix),
60
+
- yield magick_path(libwand), magick_path(libwand)
62
+
- libwand = 'lib', 'libMagickWand{0}.so'.format(suffix),
63
+
- yield magick_path(libwand), magick_path(libwand)
64
+
- if system == 'Windows':
65
+
- libwand = ctypes.util.find_library('CORE_RL_wand_' + suffix)
66
+
- libmagick = ctypes.util.find_library('CORE_RL_magick_' + suffix)
67
+
- yield libwand, libmagick
68
+
- libwand = ctypes.util.find_library('libMagickWand' + suffix)
69
+
- libmagick = ctypes.util.find_library('libMagickCore' + suffix)
70
+
- yield libwand, libmagick
72
+
- libwand = ctypes.util.find_library('MagickWand' + suffix)
73
+
- yield libwand, libwand
76
+
-def load_library():
77
+
- """Loads the MagickWand library.
79
+
- :returns: the MagickWand library and the ImageMagick library
80
+
- :rtype: :class:`ctypes.CDLL`
84
+
- for libwand_path, libmagick_path in library_paths():
85
+
- if libwand_path is None or libmagick_path is None:
88
+
- tried_paths.append(libwand_path)
89
+
- libwand = ctypes.CDLL(libwand_path)
90
+
- if libwand_path == libmagick_path:
91
+
- libmagick = libwand
93
+
- tried_paths.append(libmagick_path)
94
+
- libmagick = ctypes.CDLL(libmagick_path)
95
+
- except (IOError, OSError):
97
+
- return libwand, libmagick
98
+
- raise IOError('cannot find library; tried paths: ' + repr(tried_paths))
101
+
if not hasattr(ctypes, 'c_ssize_t'):
102
+
if ctypes.sizeof(ctypes.c_uint) == ctypes.sizeof(ctypes.c_void_p):
103
+
ctypes.c_ssize_t = ctypes.c_int
104
+
@@ -176,43 +84,14 @@ class AffineMatrix(ctypes.Structure):
105
+
# Preserve the module itself even if it fails to import
106
+
sys.modules['wand._api'] = sys.modules['wand.api']
109
+
- libraries = load_library()
110
+
-except (OSError, IOError):
111
+
- msg = 'http://docs.wand-py.org/en/latest/guide/install.html'
112
+
- if sys.platform.startswith(('dragonfly', 'freebsd')):
113
+
- msg = 'pkg install'
114
+
- elif sys.platform == 'win32':
115
+
- msg += '#install-imagemagick-on-windows'
116
+
- elif sys.platform == 'darwin':
117
+
- mac_pkgmgrs = {'brew': 'brew install freetype imagemagick',
118
+
- 'port': 'port install imagemagick'}
119
+
- for pkgmgr in mac_pkgmgrs:
120
+
- with os.popen('which ' + pkgmgr) as f:
121
+
- if f.read().strip():
122
+
- msg = mac_pkgmgrs[pkgmgr]
125
+
- msg += '#install-imagemagick-on-mac'
127
+
- distname, _, __ = platform.linux_distribution()
128
+
- distname = (distname or '').lower()
129
+
- if distname in ('debian', 'ubuntu'):
130
+
- msg = 'apt-get install libmagickwand-dev'
131
+
- elif distname in ('fedora', 'centos', 'redhat'):
132
+
- msg = 'yum install ImageMagick-devel'
133
+
- raise ImportError('MagickWand shared library not found.\n'
134
+
- 'You probably had not installed ImageMagick library.\n'
135
+
- 'Try to install:\n ' + msg)
137
+
#: (:class:`ctypes.CDLL`) The MagickWand library.
138
+
-library = libraries[0]
139
+
+library = ctypes.CDLL("@magick_wand_library@")
141
+
#: (:class:`ctypes.CDLL`) The ImageMagick library. It is the same with
142
+
#: :data:`library` on platforms other than Windows.
144
+
#: .. versionadded:: 0.1.10
145
+
-libmagick = libraries[1]
146
+
+libmagick = ctypes.CDLL("@imagemagick_library@")
149
+
library.MagickWandGenesis.argtypes = []