Bacon / BaconQrCode

QR Code Generator for PHP
BSD 2-Clause "Simplified" License
1.83k stars 208 forks source link

Make EPS & SVG Rendering usable on international locales #84

Closed bardiir closed 6 months ago

bardiir commented 3 years ago

Funnily enough - This does not fix the Imagick rendering as even the base PHP function of ImagickDraw::scale(float, float) does fail on international locale with floats. But it does take care of localized numeric transformations giving broken SVGs when using the library, it's at least usable with the svg and eps backends without giving spontaneous errors.

I also opened an issue there: https://github.com/Imagick/imagick/issues/404

The error you're seeing when using Imagick Backend on an international locale is going to be 'non-conforming drawing primitive definition `'

I'm probably still going to use an en_US locale now and do numeric transformations manually instead of via PHP instead. But it's anyway a good idea to support other locales, so this is at least an improvement over the original.

DASPRiD commented 3 years ago

Generally looks fine, though two things about this:

As %F does not omit trailing zeros, an alternative could be to have a helper function in the respective renderers which replaces the call to round() and instead use its own implementation which outputs non-locale aware numbers as strings.

Considering the last PR, it should actually be fine to combine number_format() with round() in its own function.

Francismori7 commented 3 years ago

Please merge this. On a French production server, scale gets rendered as 2,572 instead of 2.572 which in turn causes a very big scaling problem.

We're currently resorting to a STR_REPLACE around the generate function and is not really ideal.

SerkanBe commented 2 years ago

Ran into the same issue, setting the locale settings now around the QR-generation. Not ideal, but does the job. Without any str_replace or changes to the classes.

$locale = setlocale(LC_ALL, 0);
setlocale(LC_ALL, 'C');
try {
    $renderer = new ImageRenderer(
        new RendererStyle(132, 2),
        new SvgImageBackEnd()
    );

    $writer = new Writer($renderer);
    return $writer->writeString($data);
} finally {
    setlocale(LC_ALL, $locale);
}

Would it make sense to have this done in writeString()? I might be missing something... but it seems to work for me just fine.

DASPRiD commented 6 months ago

This has been addressed by #100.