Skip to content

Commit

Permalink
Merge 449237d into 3c4e1c1
Browse files Browse the repository at this point in the history
  • Loading branch information
azurefx committed Dec 1, 2018
2 parents 3c4e1c1 + 449237d commit a9828a4
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
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
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
@@ -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 a9828a4

Please sign in to comment.