Skip to content

Documentation for RendererStyle and Fill to set foregroundColor and backgroundColor #91

Closed

Description

@danielmreck

Do we have more thorough documentation available beyond what's in README.md? I've searched up and down and most of the examples I find elsewhere seem to rely on the previous version and do not work with 2.0.0.

For instance, I'd like to change the foreground and background colors of the QR code. The constructor for RendererStyle in RendererStyle.php appears to provide access for this in the fifth argument. In the Fill constructor in Fill.php there are references to foregroundColor and backgroundColor.

However, I cannot determine the combination of use statements, classes, and method calls required to actually set the colors. May we have a bit of documentation added to README.md or the wiki demonstrating this functionality?

Likewise, is there information about setting the bit-depth of generated PNGs? The default output is not compatible with FPDF.

Thank you.

Activity

  1. joldnl commented on Sep 22, 2021

    @joldnl
  2. DASPRiD commented on Sep 22, 2021

    @DASPRiD
    Member

    I'm open to accepting pull requests.

  3. joldnl commented on Sep 22, 2021

    @joldnl

    I am struggling with using modules and gradients, among other things. Ive managed to use background, foreground and eye colors, but that's about it.
    Documentation and working examples would be very welcome.

    My code for now:

    <?php
    
    require 'vendor/autoload.php';
    
    use BaconQrCode\Renderer\ImageRenderer;
    use BaconQrCode\Renderer\Image\ImagickImageBackEnd;
    use BaconQrCode\Renderer\RendererStyle\RendererStyle;
    use BaconQrCode\Renderer\RendererStyle\Fill;
    use BaconQrCode\Writer;
    
    $backgroundColor = new \BaconQrCode\Renderer\Color\Rgb(255, 255, 255);
    $foregroundColor = new \BaconQrCode\Renderer\Color\Rgb(1, 101, 185);
    $eyeColor        = new \BaconQrCode\Renderer\Color\Rgb(254,145,2);
    
    $eyeFill         = new BaconQrCode\Renderer\RendererStyle\EyeFill($eyeColor, $eyeColor);
    $fill = Fill::withForegroundColor($backgroundColor, $foregroundColor, $eyeFill, $eyeFill, $eyeFill);
    
    $renderer = new ImageRenderer(
        new RendererStyle(300, 0, null, null, $fill),
        new ImagickImageBackEnd()
    );
    
    $writer = new Writer($renderer);
    $writer->writeFile('https://www.youtube.com/watch?v=EKLnEQWOYwI', './temp/qrcode.png');
    
    ?>
    
    <img src="/temp/qrcode.png" alt="">
    
  4. locked and limited conversation to collaborators on Mar 16, 2026
  5. converted this issue into a discussion #225 on Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions