Upgrade to 4.3.0

This commit is contained in:
Bastian Allgeier
2024-06-13 12:13:00 +02:00
parent 4b55753c46
commit e50c0341fc
87 changed files with 643 additions and 430 deletions

View File

@@ -59,13 +59,15 @@ class QrCode
* @param int|null $size Image width/height in pixels, defaults to a size per module of 4x4
* @param string $color Foreground color in hex format
* @param string $back Background color in hex format
* @param int $border Border size in number of modules
*/
public function toDataUri(
int|null $size = null,
string $color = '#000000',
string $back = '#ffffff'
string $back = '#ffffff',
int $border = 4
): string {
$image = $this->toImage($size, $color, $back);
$image = $this->toImage($size, $color, $back, $border);
ob_start();
imagepng($image);
@@ -82,14 +84,16 @@ class QrCode
* @param int|null $size Image width/height in pixels, defaults to a size per module of 4x4
* @param string $color Foreground color in hex format
* @param string $back Background color in hex format
* @param int $border Border size in number of modules
*/
public function toImage(
int|null $size = null,
string $color = '#000000',
string $back = '#ffffff'
string $back = '#ffffff',
int $border = 4
): GdImage {
// get code and size measurements
$code = $this->encode();
$code = $this->encode($border);
[$width, $height] = $this->measure($code);
$size ??= ceil($width * 4);
$ws = $size / $width;
@@ -132,13 +136,15 @@ class QrCode
* @param int|string|null $size Optional CSS width of the `<svg>` element
* @param string $color Foreground color in hex format
* @param string $back Background color in hex format
* @param int $border Border size in number of modules
*/
public function toSvg(
int|string|null $size = null,
string $color = '#000000',
string $back = '#ffffff'
string $back = '#ffffff',
int $border = 4
): string {
$code = $this->encode();
$code = $this->encode($border);
[$vbw, $vbh] = $this->measure($code);
$modules = $this->eachModuleGroup(
@@ -167,15 +173,17 @@ class QrCode
* @param int|string|null $size Optional image width/height in pixels (defaults to a size per module of 4x4) or CSS width of the `<svg>` element
* @param string $color Foreground color in hex format
* @param string $back Background color in hex format
* @param int $border Border size in number of modules
*/
public function write(
string $file,
int|string|null $size = null,
string $color = '#000000',
string $back = '#ffffff'
string $back = '#ffffff',
int $border = 4
): void {
$format = F::extension($file);
$args = [$size, $color, $back];
$args = [$size, $color, $back, $border];
match ($format) {
'gif' => imagegif($this->toImage(...$args), $file),
@@ -395,7 +403,7 @@ class QrCode
return $result;
}
protected function encode(): array
protected function encode(int $q = 4): array
{
[$data, $version, $ecl, $ec] = $this->encodeData();
$data = $this->encodeErrorCorrection($data, $ec, $version);
@@ -404,7 +412,7 @@ class QrCode
$mtx = $this->finalizeMatrix($mtx, $size, $ecl, $mask, $version);
return [
'q' => [4, 4, 4, 4],
'q' => [$q, $q, $q, $q],
'size' => [$size, $size],
'bits' => $mtx
];