diff --git a/Project.toml b/Project.toml index 2ac60cf..f5602ce 100644 --- a/Project.toml +++ b/Project.toml @@ -11,7 +11,7 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" [compat] FileIO = "1" ImageCore = "0.8.1, 0.9" -ImageMagick_jll = "= 6.9.10" +ImageMagick_jll = "=6.9.10, =6.9.11" julia = "1.3" [extras] diff --git a/src/ImageMagick.jl b/src/ImageMagick.jl index 74d2408..4da34d2 100755 --- a/src/ImageMagick.jl +++ b/src/ImageMagick.jl @@ -134,14 +134,20 @@ const ufixedtype = Dict(10=>N6f10, 12=>N4f12, 14=>N2f14, 16=>N0f16) readblob(data::Vector{UInt8}) = load_(data) -function load_(file::Union{AbstractString,IO,Vector{UInt8}}, permute_horizontal=true; ImageType=Array, extraprop="", extrapropertynames=nothing, view=false) +function load_( + file::Union{AbstractString,IO,Vector{UInt8}}, permute_horizontal::Bool=true; + ImageType=Array, extraprop="", extrapropertynames=nothing, view::Bool=false, + wand::MagickWand=MagickWand(), dpi::Union{Nothing,Real}=nothing, +) if ImageType != Array error("this function now returns an Array, do not use ImageType keyword.") end if extraprop != "" || extrapropertynames != nothing error("keywords \"extraprop\" and \"extrapropertynames\" no longer work, use magickinfo instead") end - wand = MagickWand() + if dpi !== nothing + setresolution(wand, dpi, dpi) + end readimage(wand, file) resetiterator(wand) diff --git a/src/libmagickwand.jl b/src/libmagickwand.jl index 51766d7..52cd95f 100644 --- a/src/libmagickwand.jl +++ b/src/libmagickwand.jl @@ -450,3 +450,9 @@ function queryoption(option::AbstractString) p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8},), option) unsafe_string(p) end + +function setresolution(wand::MagickWand, x::Real, y::Real) + status = ccall((:MagickSetResolution, libwand), Cint, (Ptr{Cvoid}, Cdouble, Cdouble), wand, x, y) + status == 0 && error(wand) + nothing +end diff --git a/test/constructed_images.jl b/test/constructed_images.jl index bf1fc95..bab2f0a 100755 --- a/test/constructed_images.jl +++ b/test/constructed_images.jl @@ -354,4 +354,25 @@ mutable struct TestType end exportimagepixels!(buf2view, wand, cs, channelorder) @test buf2view == Ar end + + @testset "issue #206" begin + img = ImageMagick.load("images/cameraman.tif") + @test size(img) == (512, 512) + end + + if VERSION >= v"1.6" || Sys.which("gs") !== nothing + @testset "PDF" begin + pdf = ImageMagick.load("images/FLAT_-_What_is_Creative_Commons.pdf") + @test size(pdf) == (405, 720, 10) + + fn = joinpath(workdir, "cc.pdf") + ImageMagick.save(fn, pdf) + @test ImageMagick.load(fn) == pdf + + pdf_100dpi = ImageMagick.load("images/FLAT_-_What_is_Creative_Commons.pdf"; dpi=100) + @test size(pdf_100dpi) == (563, 1000, 10) + end + else + @warn "skipping PDF tests" + end end diff --git a/test/images/FLAT_-_What_is_Creative_Commons.pdf b/test/images/FLAT_-_What_is_Creative_Commons.pdf new file mode 100644 index 0000000..7048ad7 Binary files /dev/null and b/test/images/FLAT_-_What_is_Creative_Commons.pdf differ diff --git a/test/images/cameraman.tif b/test/images/cameraman.tif new file mode 100644 index 0000000..7f21122 Binary files /dev/null and b/test/images/cameraman.tif differ