), 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 * @copyright 2023 smiley * @license MIT * * @noinspection PhpComposerExtensionStubsInspection */ declare(strict_types=1); use chillerlan\QRCode\{QRCode, QROptions}; use chillerlan\QRCode\Data\QRMatrix; use chillerlan\QRCode\Output\{QRCodeOutputException, QRMarkupSVG}; require_once __DIR__.'/../vendor/autoload.php'; 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( '%4$s', $this->options->cssClass, $this->getViewBox(), $this->options->svgPreserveAspectRatio, $this->options->eol, ($width * $this->scale), // use the scale option to modify the size ($height * $this->scale), ); if($this->options->svgAddXmlHeader){ $header = sprintf('%s%s', $this->options->eol, $header); } return $header; } public function dump(string|null $file = null):string{ $base64 = $this->options->outputBase64; // we don't want the SVG in base64 $this->options->outputBase64 = false; $svg = $this->createMarkup($file !== null); // now convert the output $im = new Imagick; $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){ // use finfo to guess the mime type $mime = (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData); if($mime === false){ throw new QRCodeOutputException('unable to detect mime type'); } $imageData = $this->toBase64DataURI($imageData); } return $imageData; } } // SVG from the basic example $options = new QROptions; $options->version = 7; $options->outputInterface = SVGConvert::class; $options->imagickFormat = 'png32'; $options->scale = 20; $options->outputBase64 = false; $options->drawLightModules = true; $options->svgUseFillAttributes = false; $options->drawCircularModules = true; $options->circleRadius = 0.4; $options->connectPaths = true; $options->keepAsSquare = [ QRMatrix::M_FINDER_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT_DARK, ]; $options->svgDefs = ' '; // render the SVG and convert to the desired ImageMagick format $image = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ'); header('Content-type: image/png'); echo $image;