From a646a0179df2c3b748e6ec49b8990a34b0b7ebbc Mon Sep 17 00:00:00 2001 From: Carlo Date: Mon, 2 Feb 2015 18:23:16 +0100 Subject: [PATCH] auto detection of ImageMagick binary on Windows retrieves the ImageMagick binary path from the Windows registry --- moviepy/config.py | 21 +++++++++++++++++++-- moviepy/config_defaults.py | 2 +- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/moviepy/config.py b/moviepy/config.py index 403b2fdce..fd40384fa 100644 --- a/moviepy/config.py +++ b/moviepy/config.py @@ -4,6 +4,12 @@ from subprocess import DEVNULL # py3k except ImportError: DEVNULL = open(os.devnull, 'wb') + +if os.name == 'nt': + try: + import winreg as wr # py3k + except: + import _winreg as wr # py2k from .config_defaults import (FFMPEG_BINARY, IMAGEMAGICK_BINARY) @@ -48,11 +54,22 @@ def try_cmd(cmd): if IMAGEMAGICK_BINARY=='auto-detect': - - if try_cmd(['convert'])[0]: + if os.name == 'nt': + try: + key = wr.OpenKey(wr.HKEY_LOCAL_MACHINE, 'SOFTWARE\\ImageMagick\\Current') + IMAGEMAGICK_BINARY = wr.QueryValueEx(key, 'BinPath')[0] + r"\convert.exe" + key.Close() + except: + IMAGEMAGICK_BINARY = 'unset' + elif try_cmd(['convert'])[0]: IMAGEMAGICK_BINARY = 'convert' else: IMAGEMAGICK_BINARY = 'unset' +else: + success, err = try_cmd([IMAGEMAGICK_BINARY]) + if not success: + raise IOError(err.message + + "The path specified for the ImageMagick binary might be wrong") diff --git a/moviepy/config_defaults.py b/moviepy/config_defaults.py index 8ab73cb48..f98c88d93 100644 --- a/moviepy/config_defaults.py +++ b/moviepy/config_defaults.py @@ -48,4 +48,4 @@ """ FFMPEG_BINARY = 'ffmpeg-imageio' -IMAGEMAGICK_BINARY = 'convert' \ No newline at end of file +IMAGEMAGICK_BINARY = 'auto-detect' \ No newline at end of file