Giter Site home page Giter Site logo

Comments (4)

DASPRiD avatar DASPRiD commented on August 24, 2024 1

This should be fixed with the new PNG renderer in version 2.0.0, by the way.

from baconqrcode.

DASPRiD avatar DASPRiD commented on August 24, 2024

I just took a couple of minutes to look into the issue (I didn't touch this library in a while), which is actually rather complicated. To break it down: The renderer will add a quiet zone to make sure that each single block takes up a fixed amount of pixels.

In your second QR code, there are 73 blocks in both directions. Given an image size of 210, which does not fit a block size of 3 pixels, it has to add padding so it can place blocks with a size of 2 pixels.

There is no proper way to work around this in the library. The best you can do, if you want consistent bitmap sizes and no quiet zone, is to render the image in a higher resolution (like, twice as big), then trim the image borders (Imagick can do that with a single method call) and then downscale it to 210 pixels, which would give you anti-aliased blocks.

If you have any further comments or ideas, feel free to re-open this issue.

from baconqrcode.

temuri416 avatar temuri416 commented on August 24, 2024

ok, thanks for looking into it.

do you know if there's a certain attribute of renderer class that would tell me that extra padding was applied?

from baconqrcode.

DASPRiD avatar DASPRiD commented on August 24, 2024

Nope, the renderers won't tell you that. But as I said, this is what you can do:

// Create writer with size 420…

$image = new Imagick();
$image->readImageBlob($writer->writeString('…'));
$image->trimImage(0);
$image->resizeImage(210, 210, Imagick::FILTER_CATROM, 1);
$image->writeImage('qr-code.png');

from baconqrcode.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.