Bacon / BaconQrCode

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

Eye Square with Rounded Corner - Just a Question, not an Issue #116

Closed SergiuPogorDev closed 6 months ago

SergiuPogorDev commented 1 year ago

I'm trying to write a new Module Renderer for Eye(internal and external) in order to get Square with Rounded Corner(not circle) but not sure how to get that.

I mean, using matrix logic how to achieve this?

For Circle I use this one:

      ->move(3.5, 0)
      ->ellipticArc(3.5, 3.5, 0., false, true, 0., 3.5)
      ->ellipticArc(3.5, 3.5, 0., false, true, -3.5, 0.)
      ->ellipticArc(3.5, 3.5, 0., false, true, 0., -3.5)
      ->ellipticArc(3.5, 3.5, 0., false, true, 3.5, 0.)
      ->close()
      ->move(2.5, 0)
      ->ellipticArc(2.5, 2.5, 0., false, true, 0., 2.5)
      ->ellipticArc(2.5, 2.5, 0., false, true, -2.5, 0.)
      ->ellipticArc(2.5, 2.5, 0., false, true, 0., -2.5)
      ->ellipticArc(2.5, 2.5, 0., false, true, 2.5, 0.)
      ->close()

Should I focus on replacing ellipticArc with a combination of line() and curve()?

Expected result: qr-code

DASPRiD commented 1 year ago

I'd recommend to build it in e.g. Inkscape and have a look at the SVG path code. You can basically do the exact same thing then in code here.

enpesavento commented 1 year ago

@SergiuPogor I did some experimenting and was able to create something similar using line() and curve().

I created a new renderer module implementing the EyeInterface and created the paths as follows:

External Path:

$outerSize = 3.5;
$outerMidPoint = 1.0;

$innerSize = 2.5;
$innerMidPoint = 1.0;

(new Path())
    ->move(0, $outerSize)
    ->line($outerMidPoint, $outerSize)
    ->curve($outerMidPoint, $outerSize, $outerSize, $outerSize, $outerSize, $outerMidPoint)
    ->line($outerSize, 0)
    ->line($outerSize, -$outerMidPoint)
    ->curve($outerSize, -$outerMidPoint, $outerSize, -$outerSize, $outerMidPoint, -$outerSize)
    ->line(0, -$outerSize)
    ->line(-$outerMidPoint, -$outerSize)
    ->curve(-$outerMidPoint, -$outerSize, -$outerSize, -$outerSize, -$outerSize, -$outerMidPoint)
    ->line(-$outerSize, 0)
    ->line(-$outerSize, $outerMidPoint)
    ->curve(-$outerSize, $outerMidPoint, -$outerSize, $outerSize, -$outerMidPoint, $outerSize)
    ->line(0, $outerSize)
    ->close()

    ->move(0, $innerSize)
    ->line($innerMidPoint, $innerSize)
    ->curve($innerMidPoint, $innerSize, $innerSize, $innerSize, $innerSize, $innerMidPoint)
    ->line($innerSize, 0)
    ->line($innerSize, -$innerMidPoint)
    ->curve($innerSize, -$innerMidPoint, $innerSize, -$innerSize, $innerMidPoint, -$innerSize)
    ->line(0, -$innerSize)
    ->line(-$innerMidPoint, -$innerSize)
    ->curve(-$innerMidPoint, -$innerSize, -$innerSize, -$innerSize, -$innerSize, -$innerMidPoint)
    ->line(-$innerSize, 0)
    ->line(-$innerSize, $innerMidPoint)
    ->curve(-$innerSize, $innerMidPoint, -$innerSize, $innerSize, -$innerMidPoint, $innerSize)
    ->line(0, $innerSize)
    ->close();

Internal Path:

$size = 1.5;
$midPoint = 0.75;

(new Path())
    ->move(0, $size)
    ->line($midPoint, $size)
    ->curve($midPoint, $size, $size, $size, $size, $midPoint)
    ->line($size, 0)
    ->line($size, -$midPoint)
    ->curve($size, -$midPoint, $size, -$size, $midPoint, -$size)
    ->line(0, -$size)
    ->line(-$midPoint, -$size)
    ->curve(-$midPoint, -$size, -$size, -$size, -$size, -$midPoint)
    ->line(-$size, 0)
    ->line(-$size, $midPoint)
    ->curve(-$size, $midPoint, -$size, $size, -$midPoint, $size)
    ->line(0, $size)
    ->close();

Here the result: test

wojoj93 commented 1 year ago

Could someone explain to me why using this code I get very poor quality rounding? Zaznaczenie_1204

Rizwansayyed786 commented 1 year ago

how can I use this to work in mine I would want to build the same QR code. I am using Laravel?

this is my current generated qr code using simple qr code fonp-qr