Skip to content

Commit 3668147

Browse files
committed
Add SVG writer option for excluding width and height attributes
1 parent 1aaaa51 commit 3668147

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/Writer/SvgWriter.php

+9-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ final class SvgWriter implements WriterInterface
1717
public const DECIMAL_PRECISION = 10;
1818
public const WRITER_OPTION_BLOCK_ID = 'block_id';
1919
public const WRITER_OPTION_EXCLUDE_XML_DECLARATION = 'exclude_xml_declaration';
20+
public const WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT = 'exclude_svg_width_and_height';
2021
public const WRITER_OPTION_FORCE_XLINK_HREF = 'force_xlink_href';
2122

2223
public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, LabelInterface $label = null, array $options = []): ResultInterface
@@ -29,13 +30,19 @@ public function write(QrCodeInterface $qrCode, LogoInterface $logo = null, Label
2930
$options[self::WRITER_OPTION_EXCLUDE_XML_DECLARATION] = false;
3031
}
3132

33+
if (!isset($options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT])) {
34+
$options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT] = false;
35+
}
36+
3237
$matrixFactory = new MatrixFactory();
3338
$matrix = $matrixFactory->create($qrCode);
3439

3540
$xml = new \SimpleXMLElement('<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"/>');
3641
$xml->addAttribute('version', '1.1');
37-
$xml->addAttribute('width', $matrix->getOuterSize().'px');
38-
$xml->addAttribute('height', $matrix->getOuterSize().'px');
42+
if (!$options[self::WRITER_OPTION_EXCLUDE_SVG_WIDTH_AND_HEIGHT]) {
43+
$xml->addAttribute('width', $matrix->getOuterSize().'px');
44+
$xml->addAttribute('height', $matrix->getOuterSize().'px');
45+
}
3946
$xml->addAttribute('viewBox', '0 0 '.$matrix->getOuterSize().' '.$matrix->getOuterSize());
4047
$xml->addChild('defs');
4148

0 commit comments

Comments
 (0)