Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow manually specifying DPI #214

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
10 changes: 8 additions & 2 deletions src/ImageMagick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions src/libmagickwand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
21 changes: 21 additions & 0 deletions test/constructed_images.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Binary file added test/images/FLAT_-_What_is_Creative_Commons.pdf
Binary file not shown.
Binary file added test/images/cameraman.tif
Binary file not shown.