Skip to content

Commit

Permalink
Fix path encoding problems for read/write functions (JuliaImages/Imag…
Browse files Browse the repository at this point in the history
…es.jl#770);

Add tests for unicode compatibility;
  • Loading branch information
azurefx committed Dec 1, 2018
1 parent 3c4e1c1 commit 449237d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/libmagickwand.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ end
include("constructed_images.jl")
include("readremote.jl")
include("badimages.jl")
include("unicode.jl")

workdir = joinpath(tempdir(), "Images")
try
Expand Down
51 changes: 51 additions & 0 deletions test/unicode.jl
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 449237d

Please sign in to comment.