diff --git a/src/libmagickwand.jl b/src/libmagickwand.jl index a9bd2c9..e33e1dc 100644 --- a/src/libmagickwand.jl +++ b/src/libmagickwand.jl @@ -270,9 +270,9 @@ function pingimage(wand::MagickWand, filename::AbstractString) end function readimage(wand::MagickWand, filename::AbstractString) - status = ccall((:MagickReadImage, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}), wand, filename) - status == 0 && error(wand) - nothing + open(filename, "r") do io + readimage(wand, io) + end end function readimage(wand::MagickWand, stream::IO) @@ -288,9 +288,9 @@ function readimage(wand::MagickWand, stream::Vector{UInt8}) end function writeimage(wand::MagickWand, filename::AbstractString) - status = ccall((:MagickWriteImages, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}, Cint), wand, filename, true) - status == 0 && error(wand) - nothing + open(filename, "w") do io + writeimage(wand, io) + end end function writeimage(wand::MagickWand, stream::IO) diff --git a/test/runtests.jl b/test/runtests.jl index b933ca2..fa75d2f 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,6 +15,7 @@ end include("constructed_images.jl") include("readremote.jl") include("badimages.jl") +include("unicode.jl") workdir = joinpath(tempdir(), "Images") try diff --git a/test/unicode.jl b/test/unicode.jl new file mode 100644 index 0000000..57cebc8 --- /dev/null +++ b/test/unicode.jl @@ -0,0 +1,51 @@ +using ImageMagick, ColorTypes, FileIO +using Test + +cjkchars = "\xe4\xb8\xad\xe6\x96\x87\x20\xe6\x97\xa5\xe6\x9c\xac\xe8\xaa\x9e\x20\xed\x95\x9c\xea\xb5\xad\xec\x96\xb4" + +workdir = joinpath(tempdir(), "Images") +cjkdir = joinpath(workdir, cjkchars) +if !isdir(workdir) + mkdir(workdir) +end +if !isdir(cjkdir) + mkdir(cjkdir) +end + +@testset "Unicode compatibility" begin + + @testset "Unicode path names" begin + img = [RGB(1, 0, 0) RGB(0, 1, 0);RGB(0, 0, 1) RGB(1, 1, 1)] + fn = joinpath(cjkdir, cjkchars * ".png") + x = nothing + open(fn, "w") do io + @test try + ImageMagick.save(Stream(format"PNG", io), img);true + catch + false + end + end + @test try + x = ImageMagick.load(fn);true + catch + false + end + @test x == img + @test try + ImageMagick.save(fn, img);true + catch + false + end + open(fn, "r") do io + @test try + x = ImageMagick.load(io);true + catch + false + end + @test x == img + end + end + +end + +nothing