Skip to content

imagickFormat SVG producess invalid SVG #167

Description

@muuvmuuv

Describe the bug

I am trying to process the Imagick image after generation but with no possible option it seems right for me.

I have the imagick ext installed on PHP 8.1 and "libmagickcore-dev" (seems the one with SVG support).

This is the cachefile output:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="105" height="105">
stroke:#000000000000;fill:#000000000000;  <rect x="0" y="0" width="5" height="5"/>
stroke:#000000000000;fill:#000000000000;  <rect x="5" y="0" width="5" height="5"/>
stroke:#000000000000;fill:#000000000000;  <rect x="10" y="0" width="5" height="5"/>
stroke:#000000000000;fill:#000000000000;  <rect x="15" y="0" width="5" height="5"/>

This is the output SVG from Imagick:

<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg width="105" height="105">
<g style="fill:black;fill-opacity:1;stroke:none;stroke-width:1;stroke-opacity:1;fill-rule:nonzero;">
<g style="">
  <rect x="0" y="0" width="5" height="5"/>
</g>
<g style="">
  <rect x="5" y="0" width="5" height="5"/>
</g>

Code sample

<?php

use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;

$qr = new QRCode(new QROptions([
	'outputType' => QRCode::OUTPUT_IMAGICK,
	// 'eccLevel' => QRCode::ECC_M,
	'imagickFormat' => 'svg',
	'imagickBG' => '#fff',
	'imageTransparent' => true,
	'imageTransparencyBG' => [100, 100, 100],
	'addQuietzone' => false,
	'markupLight' => '#fff',
	'markupDark' => '#000',
]));

$blob = $qr->render($content);

$img = new \Imagick();
$img->readImageBlob($blob);

$img->writeImage($file->path . '.post.svg');

// $img->setOption('png:compression-level', 6);
$img->resizeImage($size, $size, \Imagick::FILTER_LANCZOS, 1);
// $img->setImageFormat('png');

$img->writeImage($file->path . '.png');

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • PHP version/OS: PHP 8.1, latest Debian
  • Library version: latest

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions