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

Kanji Mode QR code is broken #172

Open
askdkc opened this issue Mar 21, 2024 · 0 comments
Open

Kanji Mode QR code is broken #172

askdkc opened this issue Mar 21, 2024 · 0 comments

Comments

@askdkc
Copy link
Contributor

askdkc commented Mar 21, 2024

Although a recent pull request (#170) fixed encoding errors for Shift-JIS, generating QR codes in Kanji mode still presents issues with readability. For instance, attempting to generate a QR code using only Kanji characters results in an unreadable code.

For Kanji Mode example:

use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$renderer = new ImageRenderer(
  new RendererStyle(400),
  new ImagickImageBackEnd()
);
$writer = new Writer($renderer);
$writer->writeFile("あいうえお", "qrcode-alphanum.png", "SHIFT-JIS"); // Kanji Mode is used

Generated QR code (unreadable)

qrcode-kanjimode

However, by including alphanumeric characters and switching to Byte mode, a readable QR code can be generated.

For Byte Mode example:

use BaconQrCode\Renderer\ImageRenderer;
use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
use BaconQrCode\Writer;

$renderer = new ImageRenderer(
  new RendererStyle(400),
  new ImagickImageBackEnd()
);
$writer = new Writer($renderer);
$writer->writeFile("あいうえお123", "qrcode-alphanum.png", "SHIFT-JIS"); // Byte Mode is used

Generated QR code (readable)

qrcode-bytemode

How to fix:

I think we should just simply use Byte Mode to generate Shift-JIS encoded QR Code by changing this code:

if (null !== $encoding && 0 === strcasecmp($encoding, 'SHIFT-JIS')) {
return self::isOnlyDoubleByteKanji($content) ? Mode::KANJI() : Mode::BYTE();
}

to this:

if (null !== $encoding && 0 === strcasecmp($encoding, 'SHIFT-JIS')) {
    return Mode::BYTE();
}
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

1 participant