opening images with unicode filepaths?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Seriema

opening images with unicode filepaths?

Post by Seriema »

Hi,

I need to open images with unicode filepaths, such as japanese characters (example: 私.tga).

I'm using MagickCore and noticed that ImageInfo::filename is a char array. I need it to use wchar_t... or at least open the FILE* ImageInfo::file some other way.

I read the image like so:

Code: Select all

wchar_t* path = L"私.tga";
ExceptionInfo *exception = AcquireExceptionInfo();
ImageInfo *image_info=CloneImageInfo((ImageInfo *) NULL);
wcstombs(image_info->filename, path, sizeof(image_info->filename)/sizeof(char)); // Here I copy the wchar_t* path to the char* filename in ImageInfo.
Image *images=ReadImage(image_info,exception);
How should I read an image that has unicode characters in the filepath?
Seriema

Post by Seriema »

Seriously, can't ImageMagick read images with unicode file paths?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Post a URL to one of your Unicode images so we can download and investigate. We need to reproduce the problem before we can offer a solution.
Seriema

Post by Seriema »

Here's one
http://www.seriema.net/uni.rar

Thank you.
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We unpacked your image and displayed and converted it without any problems. We tried both *.tga and 私.tga. We're using ImageMagick 6.3.1-5 under Fedora Core 6.
Seriema

Post by Seriema »

That's really odd, since MagickCore uses a char* for filepaths. How did you do it in code?..
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

UTF-8 unicode is designed to be storable in normal strings. Just with specal meta-charcater codes to handle the non-ascii parts. that is one character may not ne one byte.

char* is fine for unicode, you just have to know it may be unicode and use the appropriate librarys to handle the unicode strings, rather than the old one byte = one char techniques.

study it a little and you will understand.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Seriema

Post by Seriema »

On my target platform (Windows XP) the following holds true:
printf("%p\n", fopen("c:\\temp\\私.tga", "rb")); // null
printf("%p\n", _wfopen(L"c:\\temp\\私.tga", L"rb"));// works!
Im guessing Fedora Core is a bit smarter about its path handling.

So how do I pass a wchar_t* as a file path, or how do I override the file loading rutine?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

We have a patch to read Unicode filenames for Windows. Look for the patch in ImageMagick 6.3.1-6 Beta within a few days.
Seriema

Post by Seriema »

That sounds awesome! Can't wait. Thank you, I'll let you know how it goes.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Seriema wrote: Im guessing Fedora Core is a bit smarter about its path handling.


More likely the Window OS is just makign things more complex. The OS designers tend to fix things by adding replacement routines, rather than fixing the original OS routines as it is done in the UNIX.

The need to specify 'binary' for files is a case in point, dating back to the DOS days.

PS: you may have guessed, I am not a big fan of Window-doze!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Seriema

Re: opening images with unicode filepaths?

Post by Seriema »

Sorry for not writing in sooner. I did try out that patch and even version 6.3.2, but I don't see how it's fixed anything since the function still takes a regular char*. As I noted in my earlier example you have to pass a string as a wide char pointer otherwise Windows won't recognize any special characters. Did I miss something? Was a new ReadImage introduced that I didn't see?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: opening images with unicode filepaths?

Post by magick »

Our understanding is that you can UTF-8 encode your file path and pass it as a char *.
Post Reply