-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
'No such file or directory' error when path contains Chinese characters #770
Comments
FYI The system codepage for non-Unicode programs is 936(GBK)
|
Is that first line in your top post the contents of My main concern is that it looks like the error may be being thrown by the ImageMagick C library rather than Julia. If so, it may be an error in the library rather than in any of the Julia code. You might want to try some of the IM command-line tools, if possible, and see if they work. If so, then I'm afraid I'm going to have to ask you to debug this yourself, I don't have any idea how to go about setting up my machine to have Chinese-character directory names. (ImageMagick.jl is not a big or complicated package, so hopefully you'll find this fairly straightforward.) |
Thanks for your reply and suggestions. I'm going to debug on my own first. |
I've figured out that this problem is caused by ImageMagick's MagickWand C interface. The MagickReadImage function accepts a char* filename parameter, and unfortunately the CRT on Windows treats filename as MBCS encoding (The active codepage for non-Unicode programs, which is CP936 (GBK) on Simplified Chinese Windows installations). Since GBK and UTF-8 are both compatible with ASCII, this function only works on full ASCII path names, and other characters become gibberish. (In libmagickwand.jl, pkg ImageMagick) using StringEncodings
function readimage(wand::MagickWand, filename::AbstractString)
filename = encode(filename, "GBK")
status = ccall((:MagickReadImage, libwand), Cint, (Ptr{Cvoid}, Ptr{UInt8}), wand, filename)
status == 0 && error(wand)
nothing
end If we convert the string to MBCS codepage explicitly, most Chinese path names can be recognized correctly. However, it still fails when path contains non-GBK characters (Japanese, Korean, etc.). A better approach is using Julia's IO facilities to bypass the CRT's file functions: using Images
using FileIO
io=open("img1.jpg","r")
img=load(io)
show(img)
close(io) I think some functions need to be re-designed to work with encodings correctly, but I can't come up with a good solution. Should we wrap those functions which accept filename with Julia IO or convert the string encoding to make IM happy? |
Nice work! You clearly know a lot more about this than I do, so the guidance I can offer is limited. Others should feel free to chime in here. Naively, I'd suggest trying the JuliaIO route first and see if tests pass; if that works, also try loading images from TestImages.jl. If those pass, perhaps that's the way to go. |
…es.jl#770); Add tests for unicode compatibility;
Fixed in my PR. #using fixed ImageMagick.jl
using TestImages
using FileIO
dir = joinpath(tempdir(), "中文路径")
if !isdir(dir)
mkdir(dir)
end
filenames = TestImages.remotefiles
for fn in filenames
imgpath = joinpath(dir, fn)
cp(joinpath(TestImages.imagedir, fn), imgpath;force = true)
img = load(imgpath)
println(size(img))
end Test images also pass. However I encountered a new problem with IM... |
It looks like this is still an issue, this post suggest that Images.jl cannot be used by people with a Chinese username on windows :( https://stackoverflow.com/questions/79032378/big-problems-caused-by-chinese-usernames-in-julia |
The text was updated successfully, but these errors were encountered: