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

added support for custom renderers #258

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

adrum
Copy link

@adrum adrum commented Sep 8, 2022

This adds the ability to pass your own custom renderers to the Generator class for both the module and the eye.

@SimplyCorey
Copy link
Member

Thanks @adrum Can you provide a few code samples with a custom module/eye just so I can test please.

@adrum
Copy link
Author

adrum commented Sep 10, 2022

Hey @SimplyCorey. I do have a custom eye, but not a custom module. Here's some ways to help test this:

       $generator
            ->size(1500)
            ->format('png')
            ->eye(\App\Utilities\SimpleQrCodeRoundedEye::class)
            ->style('round', 0.5)
            ->color(25, 29, 50)
            ->generate($url, $path);

SimpleQrCodeRoundedEye.php

<?php

namespace App\Utilities;

use BaconQrCode\Renderer\Path\Path;
use SimpleSoftwareIO\QrCode\Singleton;
use BaconQrCode\Renderer\Eye\EyeInterface;

/**
 * Renders the inner eye as a rounded square.
 */
final class SimpleQrCodeRoundedEye implements EyeInterface, Singleton
{
    /**
     * @var self|null
     */
    private static $instance;

    private function __construct()
    {
    }

    public static function instance(): self
    {
        return self::$instance ?: self::$instance = new self();
    }

    public function getExternalPath(): Path
    {
        return (new Path())
        ->move(3.5, -2.0)
        ->line(3.5, 2.0)
        ->curve(3.5, 2.75, 2.75, 3.5, 2.0, 3.5)
        ->line(-2.0, 3.5)
        ->curve(-2.75, 3.5, -3.5, 2.75, -3.5, 2.0)
        ->line(-3.5, -2.0)
        ->curve(-3.5, -2.75, -2.75, -3.5, -2.0, -3.5)
        ->line(2.0, -3.5)
        ->curve(2.75, -3.5, 3.5, -2.75, 3.5, -2.0)
        ->close()
        ->move(2.5, -1.5)
        ->line(2.5, 1.5)
        ->curve(2.5, 2.0, 2.0, 2.5, 1.5, 2.5)
        ->line(-1.5, 2.5)
        ->curve(-2.0, 2.5, -2.5, 2.0, -2.5, 1.5)
        ->line(-2.5, -1.5)
        ->curve(-2.5, -2.0, -2.0, -2.5, -1.5, -2.5)
        ->line(1.5, -2.5)
        ->curve(2.0, -2.5, 2.5, -2.0, 2.5, -1.5)
        ->close();
    }

    public function getInternalPath(): Path
    {
        return (new Path())
        ->move(1.5, -0.5)
        ->line(1.5, 0.5)
        ->curve(1.5, 1.0, 1.0, 1.5, 0.5, 1.5)
        ->line(-0.5, 1.5)
        ->curve(-1.0, 1.5, -1.5, 1.0, -1.5, 0.5)
        ->line(-1.5, -0.5)
        ->curve(-1.5, -1.0, -1.0, -1.5, -0.5, -1.5)
        ->line(0.5, -1.5)
        ->curve(1.0, -1.5, 1.5, -1.0, 1.5, -0.5)
        ->close();
    }
}

In theory, you could test the module via:

$generator->style(\BaconQrCode\Renderer\Module\RoundnessModule::class, 0.5);

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

Successfully merging this pull request may close these issues.

None yet

2 participants