Skip to content

Commit 652157a

Browse files
committed
Use compression level instead of quality
1 parent aea5455 commit 652157a

2 files changed

Lines changed: 27 additions & 5 deletions

File tree

README.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,32 @@ $dataUri = $result->getDataUri();
113113

114114
### Writer options
115115

116+
Some writers provide writer options. Each available writer option is can be
117+
found as a constant prefixed with WRITER_OPTION_ in the writer class.
118+
119+
* `PdfWriter`
120+
* `unit`: unit of measurement (default: mm)
121+
* `fpdf`: PDF to place the image in (default: new PDF)
122+
* `x`: image offset (default: 0)
123+
* `y`: image offset (default: 0)
124+
* `PngWriter`
125+
* `compression_level`: compression level (0-9, default: -1 = zlib default)
126+
* `SvgWriter`
127+
* `block_id`: id of the block element for external reference (default: block)
128+
* `exclude_xml_declaration`: exclude XML declaration (default: false)
129+
* `exclude_svg_width_and_height`: exclude width and height (default: false)
130+
* `force_xlink_href`: forces xlink namespace in case of compatibility issues (default: false)
131+
* `WebPWriter`
132+
* `quality`: image quality (0-100, default: 80)
133+
134+
You can provide any writer options like this.
135+
116136
```php
117137
use Endroid\QrCode\Writer\SvgWriter;
118138

119-
$builder->setWriterOptions([SvgWriter::WRITER_OPTION_EXCLUDE_XML_DECLARATION => true]);
139+
$builder->setWriterOptions([
140+
SvgWriter::WRITER_OPTION_EXCLUDE_XML_DECLARATION => true
141+
]);
120142
```
121143

122144
### Encoding

src/Writer/PngWriter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313

1414
final class PngWriter extends AbstractGdWriter
1515
{
16-
public const WRITER_OPTION_QUALITY = 'quality';
16+
public const WRITER_OPTION_COMPRESSION_LEVEL = 'compression_level';
1717

1818
public function write(QrCodeInterface $qrCode, LogoInterface|null $logo = null, LabelInterface|null $label = null, array $options = []): ResultInterface
1919
{
20-
if (!isset($options[self::WRITER_OPTION_QUALITY])) {
21-
$options[self::WRITER_OPTION_QUALITY] = -1;
20+
if (!isset($options[self::WRITER_OPTION_COMPRESSION_LEVEL])) {
21+
$options[self::WRITER_OPTION_COMPRESSION_LEVEL] = -1;
2222
}
2323

2424
/** @var GdResult $gdResult */
2525
$gdResult = parent::write($qrCode, $logo, $label, $options);
2626

27-
return new PngResult($gdResult->getMatrix(), $gdResult->getImage(), $options[self::WRITER_OPTION_QUALITY]);
27+
return new PngResult($gdResult->getMatrix(), $gdResult->getImage(), $options[self::WRITER_OPTION_COMPRESSION_LEVEL]);
2828
}
2929
}

0 commit comments

Comments
 (0)