endroid / qr-code

QR Code Generator
https://endroid.nl
MIT License
4.46k stars 727 forks source link

Adding label to transparent qr makes it opaque again #267

Closed MelchiorKokernoot closed 3 years ago

MelchiorKokernoot commented 4 years ago

If i configure like

$qrCode = new QrCode('https://www.google.com');

$qrCode->setSize(1000);

$qrCode->setMargin(50);

$qrCode->setWriterByName('png');

$qrCode->setEncoding('UTF-8');

$qrCode->setErrorCorrectionLevel(ErrorCorrectionLevel::HIGH());

$qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 127]);

$qrCode->setValidateResult(false);

$qrCode->setRoundBlockSize(true, QrCode::ROUND_BLOCK_SIZE_MODE_MARGIN);

header('Content-Type: ' . $qrCode->getContentType());

echo $qrCode->writeString();

I get a nice QR with a transparent background! But when I add:

$qrCode->setLabel('Testtest', 72,storage_path().'/app/fonts/Alata-Regular.ttf', LabelAlignment::CENTER());

The transparent background turns opaque again.

rolinger commented 3 years ago

What is the a parameter in $qrCode->setBackgroundColor(['r' => 255, 'g' => 255, 'b' => 255, 'a' => 127]); ???

I read through all the documentation and can't find it. I assume its a transparency value of some sort. Can it also be applied to the setForegroundColor parameter as well?

endroid commented 3 years ago

Hi @rolinger, "a" stands for alpha and can be applied to the foreground color as well ;)

endroid commented 3 years ago

@MelchiorKokernoot this should be fixed.