2

I have found that GraphicsMagick is unable to process my files named in Chinese. I did the same test on ImageMagick but IM worked as expected.

I thought this might be a bug so I filed a bug report here: https://sourceforge.net/p/graphicsmagick/bugs/384/

Anyway, this is how to reproduce my situation:

  • Platform: Win10
  • Version: GraphicsMagick 1.3.20
  • Code: gm -identify 獅藝學會.jpg

This is the returned text from Command Prompt:

>gm -identify 獅藝學會.jpg
gm identify: Unable to open file (????.jpg) [Invalid argument].
gm identify: Request did not return an image.

Using IM worked:

identify 獅藝學會.jpg
ç?.è-?å-,æoƒ.jpg JPEG 3264x2448 3264x2448+0+0 8-bit sRGB 2.691MB 0.016u 0:00.004

Although the text returned is scrambled, but converting the file to a .png still maintained the same filename apart from the different extensions of course.

What happened

I found this problem by using the gm node.js library batch processing my images, the source of the call is made from a UTF-8 webpage, so I assume the filename is passed as Unicode encoding.

I found no documentation related to this problem, although the documentation states that there was a -encoding option, it cannot be sent as parameter on Windows as it does not recognize it and I cannot find relevant solutions on Google.

Please help, is there any easy way around this problem, while keeping the exact filename?

Daniel Cheung
  • 4,779
  • 1
  • 30
  • 63

2 Answers2

2

In case someone uses the C api. (You can only give (char *)-type filenames. And UTF-8 encoding does not work, if using GraphicsMagick on Windows.)

You could do the following:

Open the file for input (or output) yourself (use fopen(), _wfopen() etc).

Then set the filehandle within the ImageInfo structure for reading and Image structure for writing respectively (instead of setting the filename).

To have GraphicsMagick generate the right output file format, set magick within the Image structure.

f.e.:

//Reading
imageInfo->file=_wfopen(input_filename,L"rb"); //ImageInfo *imageInfo;
ReadImage(imageInfo,exception);

//Writing
image->file=_wfopen(output_filename,L"wb"); //Image *image;
strcpy(image->magick,"PNG");            
WriteImage(imageInfo,image);

GraphicsMagick automatically closes the file after writing/reading.

Andy
  • 21
  • 3
0

I have the same problem using GM in C++. UTF-8 filenames are not supported under Windows (not even in the API!).

My workaround is to get the short path name (8.3), you can do that both using command line and Win32. However this doesn't work 100% - and if you want to save a file you have to create an empty one first to be able to get the short name.

Community
  • 1
  • 1
Sga
  • 3,608
  • 2
  • 36
  • 47