Skip to content

Commit

Permalink
Add GD Image backend
Browse files Browse the repository at this point in the history
  • Loading branch information
arxeiss committed Jul 21, 2022
1 parent 5c2d190 commit e41b372
Show file tree
Hide file tree
Showing 18 changed files with 546 additions and 22 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ BaconQrCode comes with multiple back ends for rendering images. Currently includ
- `ImagickImageBackEnd`: renders raster images using the Imagick library
- `SvgImageBackEnd`: renders SVG files using XMLWriter
- `EpsImageBackEnd`: renders EPS files
- `GDImageBackEnd`: renders raster images using the GD library
- Does not support gradient
- Does not support any curves, so you cannot use `SimpleCircleEye`, `DotsModule` and `RoundnessModule`
8 changes: 4 additions & 4 deletions src/Renderer/Eye/CompositeEye.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public function __construct(EyeInterface $externalEye, EyeInterface $internalEye
$this->internalEye = $internalEye;
}

public function getExternalPath() : Path
public function getExternalPath(bool $pathPerGridItem) : Path
{
return $this->externalEye->getExternalPath();
return $this->externalEye->getExternalPath($pathPerGridItem);
}

public function getInternalPath() : Path
public function getInternalPath(bool $pathPerGridItem) : Path
{
return $this->internalEye->getInternalPath();
return $this->internalEye->getInternalPath($pathPerGridItem);
}
}
4 changes: 2 additions & 2 deletions src/Renderer/Eye/EyeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ interface EyeInterface
*
* The path origin point (0, 0) must be anchored at the middle of the path.
*/
public function getExternalPath() : Path;
public function getExternalPath(bool $pathPerGridItem) : Path;

/**
* Returns the path of the internal eye element.
*
* The path origin point (0, 0) must be anchored at the middle of the path.
*/
public function getInternalPath() : Path;
public function getInternalPath(bool $pathPerGridItem) : Path;
}
8 changes: 4 additions & 4 deletions src/Renderer/Eye/ModuleEye.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(ModuleInterface $module)
$this->module = $module;
}

public function getExternalPath() : Path
public function getExternalPath(bool $pathPerGridItem) : Path
{
$matrix = new ByteMatrix(7, 7);

Expand All @@ -36,10 +36,10 @@ public function getExternalPath() : Path
$matrix->set(6, $y, 1);
}

return $this->module->createPath($matrix)->translate(-3.5, -3.5);
return $this->module->createPath($matrix, $pathPerGridItem)->translate(-3.5, -3.5);
}

public function getInternalPath() : Path
public function getInternalPath(bool $pathPerGridItem) : Path
{
$matrix = new ByteMatrix(3, 3);

Expand All @@ -49,6 +49,6 @@ public function getInternalPath() : Path
}
}

return $this->module->createPath($matrix)->translate(-1.5, -1.5);
return $this->module->createPath($matrix, $pathPerGridItem)->translate(-1.5, -1.5);
}
}
13 changes: 11 additions & 2 deletions src/Renderer/Eye/SimpleCircleEye.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace BaconQrCode\Renderer\Eye;

use BaconQrCode\Exception\RuntimeException;
use BaconQrCode\Renderer\Path\Path;

/**
Expand All @@ -24,8 +25,12 @@ public static function instance() : self
return self::$instance ?: self::$instance = new self();
}

public function getExternalPath() : Path
public function getExternalPath(bool $pathPerGridItem) : Path
{
if ($pathPerGridItem) {
throw new RuntimeException('Selected backend is not compatible with SimpleCircle eye, use ModuleEye');
}

return (new Path())
->move(-3.5, -3.5)
->line(3.5, -3.5)
Expand All @@ -40,8 +45,12 @@ public function getExternalPath() : Path
;
}

public function getInternalPath() : Path
public function getInternalPath(bool $pathPerGridItem) : Path
{
if ($pathPerGridItem) {
throw new RuntimeException('Selected backend is not compatible with SimpleCircle eye, use ModuleEye');
}

return (new Path())
->move(1.5, 0)
->ellipticArc(1.5, 1.5, 0., false, true, 0., 1.5)
Expand Down
13 changes: 11 additions & 2 deletions src/Renderer/Eye/SquareEye.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

namespace BaconQrCode\Renderer\Eye;

use BaconQrCode\Exception\RuntimeException;
use BaconQrCode\Renderer\Path\Path;

/**
Expand All @@ -24,8 +25,12 @@ public static function instance() : self
return self::$instance ?: self::$instance = new self();
}

public function getExternalPath() : Path
public function getExternalPath(bool $pathPerGridItem) : Path
{
if ($pathPerGridItem) {
throw new RuntimeException('Selected backend is not compatible with Square eye, use ModuleEye');
}

return (new Path())
->move(-3.5, -3.5)
->line(3.5, -3.5)
Expand All @@ -40,8 +45,12 @@ public function getExternalPath() : Path
;
}

public function getInternalPath() : Path
public function getInternalPath(bool $pathPerGridItem) : Path
{
if ($pathPerGridItem) {
throw new RuntimeException('Selected backend is not compatible with Square eye, use ModuleEye');
}

return (new Path())
->move(-1.5, -1.5)
->line(1.5, -1.5)
Expand Down
5 changes: 5 additions & 0 deletions src/Renderer/Image/EpsImageBackEnd.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ public function done() : string
return $blob;
}

public function requiresPathPerGridItem() : bool
{
return false;
}

private function drawPathOperations(Iterable $ops, &$fromX, &$fromY) : string
{
$pathData = [];
Expand Down
Loading

0 comments on commit e41b372

Please sign in to comment.