Skip to content

Commit

Permalink
Merge pull request #62 from 2amigos/develop
Browse files Browse the repository at this point in the history
Develop/master
  • Loading branch information
2amjsouza authored Oct 20, 2023
2 parents 0e8516c + c8fd3ce commit 5577f73
Show file tree
Hide file tree
Showing 25 changed files with 922 additions and 100 deletions.
55 changes: 55 additions & 0 deletions docs/helpful-guides/advance-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,60 @@ $qrCode = (new QrCode('https://2am.tech'))
->setScaleLogoHeight(false);
```

### Gradient Foreground

You can easily change from uniform to gradient color by setting
the range limit for you gradient for using the method `setForegroundEndColor`.
When you do this, the color you've set for the foreground using `setForegroundColor`
function will be taken as the start point for the gradient color.

```PHP
$qrCode = (new QrCode('https://2am.tech'))
->setForegroundColor(0, 255, 0, 70)
->setForegroundEndColor(0, 0, 255, 50);
```

By default, it will render the gradient color using a vertical orientation.
You can change it by the `setGradientType` function. It takes one parameter
to determine witch gradient type must be set.
The available types are:

* \Da\QrCode\Contracts\ColorsInterface::GRADIENT_VERTICAL
* \Da\QrCode\Contracts\ColorsInterface::GRADIENT_HORIZONTAL
* \Da\QrCode\Contracts\ColorsInterface::GRADIENT_RADIAL
* \Da\QrCode\Contracts\ColorsInterface::GRADIENT_DIAGONAL
* \Da\QrCode\Contracts\ColorsInterface::GRADIENT_INVERSE_DIAGONAL

```PHP
$qrCode = (new QrCode('https://2am.tech'))
->setForegroundColor(0, 255, 0, 70)
->setForegroundEndColor(0, 0, 255, 50)
->setGradientType(\Da\QrCode\Contracts\ColorsInterface::GRADIENT_DIAGONAL);
```

### Foreground Path Style
It is possible to change the foreground path style by using the `setPathStyle`
function. The default style will be the square pattern, and the available
styles are the following:

* \Da\QrCode\Contracts\PathStyleInterface::SQUARE;
* \Da\QrCode\Contracts\PathStyleInterface::DOTS;
* \Da\QrCode\Contracts\PathStyleInterface::ROUNDED;

```PHP
$qrCode = (new QrCode('https://2am.tech'))
->setPathStyle(\Da\QrCode\Contracts\PathStyleInterface::ROUNDED);
```

You can also set the intensity for the pattern appliance:

```PHP
$qrCode = (new QrCode('https://2am.tech'))
->setPathStyle(\Da\QrCode\Contracts\PathStyleInterface::ROUNDED)
->setPathIntensity(0.7);
```

The default value for the intensity is 1. It must be a number between 0 and 1,
otherwise an exception will be thrown.

© [2amigos](https://2am.tech/) 2013-2023
78 changes: 78 additions & 0 deletions src/Contracts/ColorsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace Da\QrCode\Contracts;

use BaconQrCode\Renderer\Color\Alpha;
use BaconQrCode\Renderer\Color\ColorInterface;
use BaconQrCode\Renderer\Color\Rgb;
use BaconQrCode\Renderer\RendererStyle\Fill;
use BaconQrCode\Renderer\RendererStyle\Gradient;
use BaconQrCode\Renderer\RendererStyle\GradientType;

interface ColorsInterface
{
public const GRADIENT_VERTICAL = 'vertical';
public const GRADIENT_HORIZONTAL = 'horizontal';
public const GRADIENT_RADIAL = 'radial';
public const GRADIENT_DIAGONAL = 'diagonal';
public const GRADIENT_INVERSE_DIAGONAL = 'diagonal_inverse';

/**
* @param Alpha|Rgb|Gradient $color
* @return void
*/
public function setForegroundColor($color): void;

/**
* @return Rgb|Alpha|Gradient
*/
public function getForegroundColor();

/**
* @param $color
* @return void
*/
public function setForegroundEndColor($color): void;

/**
* @return mixed
*/
public function getForegroundEndColor();

/**
* @param Alpha|Rgb $color
* @return void
*/
public function setBackgroundColor($color): void;

/**
* @return void
*/
public function unsetForegroundEndColor(): void;

/**
* @return Rgb|Alpha
*/
public function getBackgroundColor();

/**
* @param string $type
* @return void
*/
public function setGradientType(string $type): void;

/**
* @return GradientType
*/
public function getGradientTye();

/**
* @return Fill
*/
public function buildFillColor();

/**
* @return void
*/
public function forceUniformRgbColors(): void;
}
45 changes: 45 additions & 0 deletions src/Contracts/PathStyleInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Da\QrCode\Contracts;

use BaconQrCode\Renderer\Eye\EyeInterface;
use BaconQrCode\Renderer\Module\ModuleInterface;

interface PathStyleInterface
{
public const DOTS = 'dots';
public const SQUARE = 'square';
public const ROUNDED = 'rounded';

/**
* @param string $pathStyle
* @return void
*/
public function setPathStyle(string $pathStyle): void;

/**
* @return string
*/
public function getPathStyle(): string;

/**
* @param int $ratio
* @return void
*/
public function setIntensity(float $intensity): void;

/**
* @return float
*/
public function getIntensity(): float;

/**
* @return ModuleInterface
*/
public function buildModule();

/**
* @return EyeInterface
*/
public function buildEye();
}
8 changes: 7 additions & 1 deletion src/Contracts/QrCodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public function getForegroundColor(): array;
*/
public function getBackgroundColor(): array;

/**
* @return array|null
*/
public function getForegroundEndColor();

/**
* @return string
*/
Expand All @@ -60,8 +65,9 @@ public function getLogoWidth(): ?int;

/**
* @var
* @return bool
*/
public function getScaleLogoHeight(): bool;
public function isScaleLogoHeight(): bool;

/**
* @return LabelInterface
Expand Down
Loading

0 comments on commit 5577f73

Please sign in to comment.