mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-07 00:15:46 +00:00
:octocat: QRFpdf: support bgColor and drawLightModules
This commit is contained in:
+8
-6
@@ -13,12 +13,14 @@ use chillerlan\QRCode\Output\QROutputInterface;
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
$options = new QROptions([
|
||||
'version' => 7,
|
||||
'outputType' => QROutputInterface::FPDF,
|
||||
'eccLevel' => EccLevel::L,
|
||||
'scale' => 5,
|
||||
'imageBase64' => false,
|
||||
'moduleValues' => [
|
||||
'version' => 7,
|
||||
'outputType' => QROutputInterface::FPDF,
|
||||
'eccLevel' => EccLevel::L,
|
||||
'scale' => 5,
|
||||
'bgColor' => [234, 234, 234],
|
||||
'drawLightModules' => false,
|
||||
'imageBase64' => false,
|
||||
'moduleValues' => [
|
||||
// finder
|
||||
QRMatrix::M_FINDER | QRMatrix::IS_DARK => [0, 63, 255], // dark (true)
|
||||
QRMatrix::M_FINDER => [255, 255, 255], // light (false), white is the transparency color and is enabled by default
|
||||
|
||||
+13
-1
@@ -95,11 +95,23 @@ class QRFpdf extends QROutputAbstract{
|
||||
$fpdf = new FPDF('P', $this->options->fpdfMeasureUnit, [$this->length, $this->length]);
|
||||
$fpdf->AddPage();
|
||||
|
||||
if($this->moduleValueIsValid($this->options->bgColor)){
|
||||
$bgColor = $this->getModuleValue($this->options->bgColor);
|
||||
|
||||
$fpdf->SetFillColor(...$bgColor);
|
||||
$fpdf->Rect(0, 0, $this->length, $this->length, 'F');
|
||||
}
|
||||
|
||||
$prevColor = null;
|
||||
|
||||
foreach($this->matrix->matrix() as $y => $row){
|
||||
|
||||
foreach($row as $x => $M_TYPE){
|
||||
|
||||
if(!$this->options->drawLightModules && !$this->matrix->check($x, $y)){
|
||||
continue;
|
||||
}
|
||||
|
||||
/** @var int $M_TYPE */
|
||||
$color = $this->moduleValues[$M_TYPE];
|
||||
|
||||
@@ -109,7 +121,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
$prevColor = $color;
|
||||
}
|
||||
|
||||
$fpdf->Rect($x * $this->scale, $y * $this->scale, 1 * $this->scale, 1 * $this->scale, 'F');
|
||||
$fpdf->Rect($x * $this->scale, $y * $this->scale, $this->scale, $this->scale, 'F');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user