-
-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
132520b
commit cf7e82b
Showing
2 changed files
with
19 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,14 @@ | |
/** | ||
* SVG to raster conversion example using ImageMagick | ||
* | ||
* Please note that conversion via ImageMagick may not always produce ideal results, | ||
* especially when using CSS styling (external or via <defs>), also it depends on OS and Imagick version. | ||
* | ||
* Using the Inkscape command line may be the better option: | ||
* | ||
* @see https://wiki.inkscape.org/wiki/Using_the_Command_Line | ||
* @see https://github.com/chillerlan/php-qrcode/discussions/216 | ||
* | ||
* @created 19.09.2023 | ||
* @author smiley <[email protected]> | ||
* @copyright 2023 smiley | ||
|
@@ -22,14 +30,15 @@ class SVGConvert extends QRMarkupSVG{ | |
protected function header():string{ | ||
[$width, $height] = $this->getOutputDimensions(); | ||
|
||
// we need to specify the "width" and "height" attributes so that Imagick knows the output size | ||
$header = sprintf( | ||
'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="%2$s" preserveAspectRatio="%3$s" width="%4$s" height="%5$s">%6$s', | ||
'<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" viewBox="%2$s" preserveAspectRatio="%3$s" width="%5$s" height="%6$s">%4$s', | ||
$this->options->cssClass, | ||
$this->getViewBox(), | ||
$this->options->svgPreserveAspectRatio, | ||
($width * $this->scale), | ||
($height * $this->scale), | ||
$this->options->eol | ||
$this->options->eol, | ||
($width * $this->scale), // use the scale option to modify the size | ||
($height * $this->scale) | ||
); | ||
|
||
if($this->options->svgAddXmlHeader){ | ||
|
@@ -52,8 +61,13 @@ public function dump(string $file = null):string{ | |
$im->readImageBlob($svg); | ||
$im->setImageFormat($this->options->imagickFormat); | ||
|
||
if($this->options->quality > -1){ | ||
$im->setImageCompressionQuality(max(0, min(100, $this->options->quality))); | ||
} | ||
|
||
$imageData = $im->getImageBlob(); | ||
|
||
$im->destroy(); | ||
$this->saveToFile($imageData, $file); | ||
|
||
if($base64){ | ||
|