Browse Source

:octocat: +data-uri/base64 for SVG

codemasher 5 years ago
parent
commit
c10f5a24ec
4 changed files with 8 additions and 4 deletions
  1. 3 1
      src/Output/QRImage.php
  2. 4 0
      src/Output/QRMarkup.php
  3. 1 1
      tests/Output/QRMarkupTest.php
  4. 0 2
      tests/Output/samples/svg

+ 3 - 1
src/Output/QRImage.php

@@ -33,6 +33,8 @@ class QRImage extends QROutputAbstract{
 
 	/**
 	 * @inheritDoc
+	 *
+	 * @throws \chillerlan\QRCode\QRCodeException
 	 */
 	public function __construct(SettingsContainerInterface $options, QRMatrix $matrix){
 
@@ -115,7 +117,7 @@ class QRImage extends QROutputAbstract{
 			$this->saveToFile($imageData, $file);
 		}
 
-		if((bool)$this->options->imageBase64){
+		if($this->options->imageBase64){
 			$imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData));
 		}
 

+ 4 - 0
src/Output/QRMarkup.php

@@ -150,6 +150,10 @@ class QRMarkup extends QROutputAbstract{
 			       $this->options->eol.$svg;
 		}
 
+		if($this->options->imageBase64){
+			$svg = sprintf('data:image/svg+xml;base64,%s', base64_encode($svg));
+		}
+
 		return $svg;
 	}
 

+ 1 - 1
tests/Output/QRMarkupTest.php

@@ -43,7 +43,7 @@ class QRMarkupTest extends QROutputTestAbstract{
 	 * @inheritDoc
 	 */
 	public function testSetModuleValues():void{
-
+		$this->options->imageBase64  = false;
 		$this->options->moduleValues = [
 			// data
 			1024 => '#4A6000',

File diff suppressed because it is too large
+ 0 - 2
tests/Output/samples/svg


Some files were not shown because too many files changed in this diff