Skip to content

Commit

Permalink
Fix format inference problems with IOStream
Browse files Browse the repository at this point in the history
  • Loading branch information
azurefx committed Dec 6, 2018
1 parent 449237d commit 2900579
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/libmagickwand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,29 @@ function getblob(wand::MagickWand, format::AbstractString)
end

function pingimage(wand::MagickWand, filename::AbstractString)
#Warning: filename is not UTF-8 on Windows
status = ccall((:MagickPingImage, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}), wand, filename)
status == 0 && error(wand)
nothing
end

#MagickSetFilename for reading, MagickSetImageFilename for writing
function setfilename(wand::MagickWand, filename::AbstractString)
status = ccall((:MagickSetFilename, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}), wand, filename)
status == 0 && error(wand)
nothing
end

function setimagefilename(wand::MagickWand, filename::AbstractString)
status = ccall((:MagickSetImageFilename, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}), wand, filename)
status == 0 && error(wand)
nothing
end

function readimage(wand::MagickWand, filename::AbstractString)
open(filename, "r") do io
(_, ext) = splitext(filename)
setfilename(wand, "a"*ext)
readimage(wand, io)
end
end
Expand All @@ -289,6 +305,9 @@ end

function writeimage(wand::MagickWand, filename::AbstractString)
open(filename, "w") do io
#Let IM infer the format when writing to a stream
(_, ext) = splitext(filename)
setimagefilename(wand, "a"*ext)
writeimage(wand, io)
end
end
Expand Down

0 comments on commit 2900579

Please sign in to comment.