Skip to content
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

Cannot open file for reading if the filename contains japanese characters(non-unicode?) #376

Closed
GustJc opened this issue Apr 22, 2021 · 5 comments

Comments

@GustJc
Copy link

GustJc commented Apr 22, 2021

$ ./pngquant.exe イメージ.png
error: cannot open イメージ.png for reading

Not sure if this is a windows problem or pngquant one but when trying to unpack any images that contain japanese characters in its name it cannot read the file. The GUI tool works fine, only the cli tool doesn't in this case.

I've tried using the normal windows terminal, git bash and cygwin to see if there was any difference but the same thing happens on all of them. I can properly compress the image if I rename it to contain only ascii characters.

@kornelski
Copy link
Owner

This is a known problem of Microsoft's C standard library. Their implementation of fopen only supports old MS-DOS codepages, and doesn't support Unicode.

@GustJc
Copy link
Author

GustJc commented Apr 27, 2021

I understand it now.

I've make a quick workaround for myself to enable the conversion of those japanese named files.
This is very wrong, but it seems to work all right for me so far anyways.
Here is what I did if anyone else wants to make a personal build of it.

I've basically forced the locale before opening the file and it properly openned and compacted the image.
For reference:

#include <locale.h>

// Inside static pngquant_error read_image
setlocale(LC_ALL, ".65001");

Result:

$ ./pngquant.exe イメージ.png --verbose
イメージ.png:
  read 5KB file
  passing sRGB tag from the input
  made histogram...2 colors found
  eliminated opaque tRNS-chunk entries...0 entries transparent
  mapped image to new colors...MSE=0.000 (Q=100)
  writing 2-color image as イメージ-fs8.png
  copied 1KB of additional PNG metadata
Quantized 1 image.

@kornelski
Copy link
Owner

This is great! Thank you for the tip.

kornelski added a commit that referenced this issue Apr 27, 2021
@jibsen
Copy link
Contributor

jibsen commented Apr 29, 2021

I have no experience with this, but just wanted to note that the docs for setlocale has a section on UTF-8 support that mentions this was added in a 2018 update of Windows 10 and requires static linking to support older Windows versions.

@kornelski
Copy link
Owner

I've released 2.15.0 with this fix

@Guest126 Guest126 mentioned this issue Nov 15, 2021
kornelski added a commit that referenced this issue Nov 26, 2021
* master:
  Changelog
  Avoid deprecated field in rwpng_cocoa.rs
  ad-hoc fix #376
  Bump
  fix badge
  Travis is dead

# Conflicts:
#	lib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants