Skip to content

Commit 9cc3e3f

Browse files
committed
allow manually specifying DPI
PDFs are currently always read with the default DPI of 70, which is not particularly high. This allows manually specifying it using the `dpi` keyword. Still needs a test, is there a good sample PDF document I could use for this? cc @timholy
1 parent c2cf4f3 commit 9cc3e3f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/ImageMagick.jl

+8-2
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,20 @@ const ufixedtype = Dict(10=>N6f10, 12=>N4f12, 14=>N2f14, 16=>N0f16)
134134

135135
readblob(data::Vector{UInt8}) = load_(data)
136136

137-
function load_(file::Union{AbstractString,IO,Vector{UInt8}}, permute_horizontal=true; ImageType=Array, extraprop="", extrapropertynames=nothing, view=false)
137+
function load_(
138+
file::Union{AbstractString,IO,Vector{UInt8}}, permute_horizontal::Bool=true;
139+
ImageType=Array, extraprop="", extrapropertynames=nothing, view::Bool=false,
140+
wand::MagickWand=MagickWand(), dpi::Union{Nothing,Real}=nothing,
141+
)
138142
if ImageType != Array
139143
error("this function now returns an Array, do not use ImageType keyword.")
140144
end
141145
if extraprop != "" || extrapropertynames != nothing
142146
error("keywords \"extraprop\" and \"extrapropertynames\" no longer work, use magickinfo instead")
143147
end
144-
wand = MagickWand()
148+
if dpi !== nothing
149+
setresolution(wand, dpi, dpi)
150+
end
145151
readimage(wand, file)
146152
resetiterator(wand)
147153

src/libmagickwand.jl

+6
Original file line numberDiff line numberDiff line change
@@ -450,3 +450,9 @@ function queryoption(option::AbstractString)
450450
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8},), option)
451451
unsafe_string(p)
452452
end
453+
454+
function setresolution(wand::MagickWand, x::Real, y::Real)
455+
status = ccall((:MagickSetResolution, libwand), Cint, (Ptr{Cvoid}, Cdouble, Cdouble), wand, x, y)
456+
status == 0 && error(wand)
457+
nothing
458+
end

0 commit comments

Comments
 (0)