Просмотр исходного кода

:octocat: allow base64 output for the fpdf module

codemasher 5 лет назад
Родитель
Сommit
9f0251b466
3 измененных файлов с 7 добавлено и 1 удалено
  1. 1 0
      examples/fpdf.php
  2. 4 0
      src/Output/QRFpdf.php
  3. 2 1
      tests/Output/QRFpdfTest.php

+ 1 - 0
examples/fpdf.php

@@ -13,6 +13,7 @@ $options = new QROptions([
     'outputType'   => QRCode::OUTPUT_FPDF,
     'eccLevel'     => QRCode::ECC_L,
     'scale'        => 5,
+    'imageBase64'  => false,
     'moduleValues' => [
         // finder
         1536 => [0, 63, 255], // dark (true)

+ 4 - 0
src/Output/QRFpdf.php

@@ -102,6 +102,10 @@ class QRFpdf extends QROutputAbstract{
 			$this->saveToFile($pdfData, $file);
 		}
 
+		if($this->options->imageBase64){
+			$pdfData = sprintf('data:application/pdf;base64,%s', base64_encode($pdfData));
+		}
+
 		return $pdfData;
 	}
 

+ 2 - 1
tests/Output/QRFpdfTest.php

@@ -77,7 +77,8 @@ class QRFpdfTest extends QROutputTestAbstract{
 	 * @dataProvider types
 	 */
 	public function testRenderImage(string $type):void{
-		$this->options->outputType = $type;
+		$this->options->outputType  = $type;
+		$this->options->imageBase64 = false;
 
 		// substr() to avoid CreationDate
 		$expected = substr(file_get_contents(__DIR__.'/samples/'.$type), 0, 2500);