Skip to content

Commit

Permalink
allow manually specifying DPI
Browse files Browse the repository at this point in the history
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
  • Loading branch information
simeonschaub committed Feb 1, 2023
1 parent 079d62b commit b5d84f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
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

0 comments on commit b5d84f4

Please sign in to comment.