mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-17 15:12:32 +00:00
🚿
This commit is contained in:
@@ -29,6 +29,8 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
*/
|
||||
class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
|
||||
protected float $center;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
@@ -42,13 +44,13 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
// update the matrix dimensions to avoid errors in subsequent calculations
|
||||
// the moduleCount is now QR Code matrix + 2x quiet zone
|
||||
$this->setMatrixDimensions();
|
||||
// color the quiet zone
|
||||
$this->colorQuietzone($quietzoneSize, ($diameter / 2));
|
||||
|
||||
$this->center = ($this->moduleCount / 2);
|
||||
// calculate the logo space
|
||||
$logoSpaceSize = (int)(ceil($this->moduleCount * $this->options->svgLogoScale) + 1);
|
||||
// we're calling QRMatrix::setLogoSpace() manually, so QROptions::$addLogoSpace has no effect here
|
||||
$this->matrix->setLogoSpace($logoSpaceSize);
|
||||
// color the quiet zone
|
||||
$this->colorQuietzone($quietzoneSize, ($diameter / 2));
|
||||
|
||||
// start SVG output
|
||||
$svg = $this->header();
|
||||
@@ -64,11 +66,6 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
// close svg
|
||||
$svg .= sprintf('%1$s</svg>%1$s', $this->options->eol);
|
||||
|
||||
// transform to data URI only when not saving to file
|
||||
if(!$saveToFile && $this->options->outputBase64){
|
||||
$svg = $this->toBase64DataURI($svg, 'image/svg+xml');
|
||||
}
|
||||
|
||||
return $svg;
|
||||
}
|
||||
|
||||
@@ -109,7 +106,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
|
||||
// we need to add 0.5 units to the check values since we're calculating the element centers
|
||||
// ($x/$y is the element's assumed top left corner)
|
||||
if($this->checkIfInsideCircle(($x + 0.5), ($y + 0.5), $r)){
|
||||
if($this->checkIfInsideCircle(($x + 0.5), ($y + 0.5), $this->center, $this->center, $r)){
|
||||
$this->matrix->set($x, $y, (bool)rand(0, 1), QRMatrix::M_QUIETZONE);
|
||||
}
|
||||
}
|
||||
@@ -120,9 +117,9 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
/**
|
||||
* @see https://stackoverflow.com/a/7227057
|
||||
*/
|
||||
protected function checkIfInsideCircle(float $x, float $y, float $radius):bool{
|
||||
$dx = abs($x - $this->moduleCount / 2);
|
||||
$dy = abs($y - $this->moduleCount / 2);
|
||||
protected function checkIfInsideCircle(float $x, float $y, float $centerX, float $centerY, float $radius):bool{
|
||||
$dx = abs($x - $centerX);
|
||||
$dy = abs($y - $centerY);
|
||||
|
||||
if(($dx + $dy) <= $radius){
|
||||
return true;
|
||||
@@ -132,11 +129,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
return false;
|
||||
}
|
||||
|
||||
if((pow($dx, 2) + pow($dy, 2)) <= pow($radius, 2)){
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return (pow($dx, 2) + pow($dy, 2)) <= pow($radius, 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -145,7 +138,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
protected function addCircle(float $radius):string{
|
||||
return sprintf(
|
||||
'%4$s<circle id="circle" cx="%1$s" cy="%1$s" r="%2$s" stroke-width="%3$s"/>',
|
||||
($this->moduleCount / 2),
|
||||
$this->center,
|
||||
round($radius, 5),
|
||||
($this->options->circleRadius * 2),
|
||||
$this->options->eol
|
||||
@@ -194,7 +187,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
// randomly assign another $M_TYPE_LAYER for the given types
|
||||
// note that the layer id has to be an integer value,
|
||||
// ideally outside the several bitmask values
|
||||
if($M_TYPE_LAYER === QRMatrix::M_DATA_DARK){
|
||||
if($M_TYPE_LAYER === QRMatrix::M_QUIETZONE_DARK){
|
||||
$M_TYPE_LAYER = array_rand($dotColors);
|
||||
}
|
||||
|
||||
@@ -329,11 +322,8 @@ $options->outputBase64 = false; // avoid base64 URI output for the exampl
|
||||
$options->outputInterface = RoundQuietzoneSVGoutput::class; // load our own output class
|
||||
$options->drawLightModules = false; // set to true to add the light modules
|
||||
// common SVG options
|
||||
#$options->connectPaths = true; // this has been set to "always on" internally
|
||||
$options->connectPaths = true;
|
||||
$options->excludeFromConnect = [
|
||||
QRMatrix::M_FINDER_DARK,
|
||||
QRMatrix::M_FINDER_DOT,
|
||||
QRMatrix::M_ALIGNMENT_DARK,
|
||||
QRMatrix::M_QUIETZONE_DARK,
|
||||
];
|
||||
$options->drawCircularModules = true;
|
||||
|
||||
Reference in New Issue
Block a user