diff --git a/README.md b/README.md index d2c00e6..55816dd 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,14 @@ some of your workarounds might interfere with the new approach. You can reset yo ```julia using Homebrew -run(`brew remove imagemagick@6`) -run(`brew prune`) +Homebrew.rm("imagemagick@6") +Homebrew.brew(`prune`) Pkg.build("ImageMagick") ``` You may also find [debugging Homebrew](https://github.com/JuliaLang/Homebrew.jl/wiki/Debugging-Homebrew.jl) -useful. +useful. Finally, an alternative to ImageMagick on OS X is [QuartzImageIO](https://github.com/JuliaIO/QuartzImageIO.jl). @@ -80,7 +80,7 @@ necessary changes to take effect.** ImageMagick.jl automatically searches for an installed version of libMagickWand. Use the environment variable `MAGICK_HOME` to add to the search -path. Use `ImageMagick.libversion` to see what version it found. Version 6.7+ +path. Use `ImageMagick.libversion()` to see what version it found. Version 6.7+ (up to but not including 7.0) are the most supported versions, in particular for multipage TIFFs. diff --git a/deps/build.jl b/deps/build.jl index 9f04d71..1628ded 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -15,31 +15,17 @@ libwand = library_dependency("libwand", aliases = aliases) mpath = get(ENV, "MAGICK_HOME", "") # If MAGICK_HOME is defined, add to library search path if !isempty(mpath) - init_fun = - """ - function init_deps() - ccall((:MagickWandGenesis, libwand), Void, ()) - end - """ - - provides(Binaries, mpath, libwand, preload = init_fun, onload = "init_deps()") - provides(Binaries, joinpath(mpath, "lib"), libwand, preload = init_fun, onload = "init_deps()") + provides(Binaries, mpath, libwand) + provides(Binaries, joinpath(mpath, "lib"), libwand) end if is_linux() - init_fun = - """ - function init_deps() - ccall((:MagickWandGenesis, libwand), Void, ()) - end - """ - - provides(AptGet, "libmagickwand4", libwand, preload = init_fun, onload = "init_deps()") - provides(AptGet, "libmagickwand5", libwand, preload = init_fun, onload = "init_deps()") - provides(AptGet, "libmagickwand-6.q16-2", libwand, preload = init_fun, onload = "init_deps()") - provides(Pacman, "imagemagick", libwand, preload = init_fun, onload = "init_deps()") - provides(Yum, "ImageMagick", libwand, preload = init_fun, onload = "init_deps()") + provides(AptGet, "libmagickwand4", libwand) + provides(AptGet, "libmagickwand5", libwand) + provides(AptGet, "libmagickwand-6.q16-2", libwand) + provides(Pacman, "imagemagick", libwand) + provides(Yum, "ImageMagick", libwand) end @@ -61,12 +47,10 @@ if is_windows() magick_url = "$(magick_base)/$(magick_exe)" magick_libdir = joinpath(BinDeps.libdir(libwand), OS_ARCH) innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe" - init_fun = + preloads = """ - function init_deps() - ENV["MAGICK_CONFIGURE_PATH"] = \"$(escape_string(magick_libdir))\" - ENV["MAGICK_CODER_MODULE_PATH"] = \"$(escape_string(magick_libdir))\" - end + init_envs["MAGICK_CONFIGURE_PATH"] = \"$(escape_string(magick_libdir))\" + init_envs["MAGICK_CODER_MODULE_PATH"] = \"$(escape_string(magick_libdir))\" """ provides(BuildProcess, @@ -81,50 +65,26 @@ if is_windows() `innounp.exe -q -y -b -e -x -d$(magick_libdir) $(magick_exe)` end end), - libwand, os = :Windows, unpacked_dir = magick_libdir, preload = init_fun, - onload = "init_deps()") + libwand, os = :Windows, unpacked_dir = magick_libdir, preload = preloads) end if is_apple() using Homebrew - imagemagick_prefix = Homebrew.prefix("staticfloat/juliadeps/imagemagick@6") - init_fun = + homebrew_prefix = Homebrew.prefix() + preloads = """ - function init_deps() - ENV["MAGICK_CONFIGURE_PATH"] = joinpath("$(imagemagick_prefix)", - "lib", "ImageMagick", "config-Q16") - ENV["MAGICK_CODER_MODULE_PATH"] = joinpath("$(imagemagick_prefix)", - "lib", "ImageMagick", "modules-Q16", "coders") - ENV["PATH"] = joinpath("$(imagemagick_prefix)", "bin") * ":" * ENV["PATH"] - - ccall((:MagickWandGenesis,libwand), Void, ()) - end + init_envs["MAGICK_CONFIGURE_PATH"] = joinpath("$(homebrew_prefix)", + "lib", "ImageMagick", "config-Q16") + init_envs["MAGICK_CODER_MODULE_PATH"] = joinpath("$(homebrew_prefix)", + "lib", "ImageMagick", "modules-Q16", "coders") + init_envs["PATH"] = joinpath("$(homebrew_prefix)", "bin") * ":" * ENV["PATH"] """ - provides(Homebrew.HB, "staticfloat/juliadeps/imagemagick@6", libwand, os = :Darwin, - preload = init_fun, onload = "init_deps()") + provides(Homebrew.HB, "homebrew/core/imagemagick@6", libwand, os = :Darwin, preload = preloads) end @BinDeps.install Dict([(:libwand, :libwand)]) -# Hack-fix for issue #12 -# Check to see whether init_deps is present, and if not add it -if isempty(search(readstring(joinpath(dirname(@__FILE__),"deps.jl")), "init_deps")) - open("deps.jl", "a") do io - write(io, init_fun) - end -end - -module CheckVersion - include("deps.jl") - p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8}, ), - "LIB_VERSION_NUMBER") - vstr = string("v\"", join(split(unsafe_string(p), ',')[1:3], '.'), "\"") - open(joinpath(dirname(@__FILE__), "versioninfo.jl"), "w") do file - write(file, "const libversion = $vstr\n") - end -end - is_windows() && pop!(BinDeps.defaults) diff --git a/src/ImageMagick.jl b/src/ImageMagick.jl index 1142a65..fc03bde 100644 --- a/src/ImageMagick.jl +++ b/src/ImageMagick.jl @@ -152,7 +152,7 @@ function image2wand(img, mapi=identity, quality=nothing, permute_horizontal=true T = eltype(imgw) channelorder = T<:Real ? "Gray" : ColorTypes.colorant_string(T) if T <: Union{RGB,RGBA,ARGB,BGRA,ABGR} - cs = libversion > v"6.7.5" ? "sRGB" : "RGB" + cs = libversion() > v"6.7.5" ? "sRGB" : "RGB" else cs = channelorder end diff --git a/src/libmagickwand.jl b/src/libmagickwand.jl index df3f852..d630249 100644 --- a/src/libmagickwand.jl +++ b/src/libmagickwand.jl @@ -20,27 +20,31 @@ export MagickWand, # Find the library depsfile = joinpath(dirname(@__FILE__), "..", "deps", "deps.jl") -versionfile = joinpath(dirname(@__FILE__), "..", "deps", "versioninfo.jl") +init_envs = Dict{String,String}() if isfile(depsfile) include(depsfile) else error("ImageMagick not properly installed. Please run Pkg.build(\"ImageMagick\") then restart Julia.") # now that this is decoupled from images, should this be an error? end -if isfile(versionfile) - include(versionfile) -end const have_imagemagick = isdefined(:libwand) +const _libversion = Ref{VersionNumber}() +libversion() = _libversion[] + # Initialize the library function __init__() - init_deps() + for (key, value) in init_envs + ENV[key] = value + end !have_imagemagick && warn("ImageMagick utilities not found. Install for more file format support.") + ccall((:MagickWandGenesis, libwand), Void, ()) + p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8}, ), + "LIB_VERSION_NUMBER") + _libversion[] = VersionNumber(join(split(unsafe_string(p), ',')[1:3], '.')) end - - # Constants # Storage types const CHARPIXEL = 1 diff --git a/test/runtests.jl b/test/runtests.jl index fdc0b35..82dd555 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,6 @@ using ImageMagick -info("ImageMagick version ", ImageMagick.libversion) +info("ImageMagick version ", ImageMagick.libversion()) include("constructed_images.jl") include("readremote.jl")