Skip to content

Commit 21e888e

Browse files
committed
Also default to true color in case of transparent fore or background
1 parent 8102273 commit 21e888e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Writer/PngWriter.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ public function write(QrCodeInterface $qrCode, ?LogoInterface $logo = null, ?Lab
2323
}
2424

2525
if (!array_key_exists(self::WRITER_OPTION_NUMBER_OF_COLORS, $options)) {
26-
// When a logo is present use true color, otherwise use a palette of 16 colors
27-
$options[self::WRITER_OPTION_NUMBER_OF_COLORS] = $logo instanceof LogoInterface ? null : 16;
26+
$options[self::WRITER_OPTION_NUMBER_OF_COLORS] = match (true) {
27+
$qrCode->getBackgroundColor()->getAlpha() > 0 || $qrCode->getForegroundColor()->getAlpha() > 0 => null,
28+
$logo instanceof LogoInterface => null,
29+
default => 16,
30+
};
2831
}
2932

3033
/** @var GdResult $gdResult */

0 commit comments

Comments
 (0)