mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-08-30 03:58:28 +00:00
:octocat: allow base64 encoding for SVG and PDF output
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,10 @@ class QRMarkup extends QROutputAbstract{
|
||||
return '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">'.$this->options->eol.$svg;
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$svg = sprintf('data:image/svg+xml;base64,%s', base64_encode($svg));
|
||||
}
|
||||
|
||||
return $svg;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,8 @@ class QRFpdfTest extends QROutputTestAbstract{
|
||||
public function testRenderImage():void{
|
||||
$type = QRCode::OUTPUT_FPDF;
|
||||
|
||||
$this->options->outputType = $type;
|
||||
$this->options->outputType = $type;
|
||||
$this->options->imageBase64 = false;
|
||||
$this->outputInterface->dump($this::cachefile.$type);
|
||||
|
||||
// substr() to avoid CreationDate
|
||||
|
||||
@@ -43,7 +43,8 @@ class QRMarkupTest extends QROutputTestAbstract{
|
||||
* @param $type
|
||||
*/
|
||||
public function testMarkupOutput($type){
|
||||
$this->options->outputType = $type;
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->outputType = $type;
|
||||
$this->setOutputInterface();
|
||||
|
||||
$expected = explode($this->options->eol, file_get_contents($this::cachefile.$type));
|
||||
@@ -62,6 +63,7 @@ class QRMarkupTest extends QROutputTestAbstract{
|
||||
|
||||
public function testSetModuleValues(){
|
||||
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->moduleValues = [
|
||||
// data
|
||||
1024 => '#4A6000',
|
||||
|
||||
@@ -56,7 +56,7 @@ class QRCodeTest extends QRTestAbstract{
|
||||
'png' => [QRCode::OUTPUT_IMAGE_PNG, 'data:image/png;base64,'],
|
||||
'gif' => [QRCode::OUTPUT_IMAGE_GIF, 'data:image/gif;base64,'],
|
||||
'jpg' => [QRCode::OUTPUT_IMAGE_JPG, 'data:image/jpg;base64,'],
|
||||
'svg' => [QRCode::OUTPUT_MARKUP_SVG, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" class="qr-svg " style="width: 100%; height: auto;" viewBox="'],
|
||||
'svg' => [QRCode::OUTPUT_MARKUP_SVG, 'data:image/svg+xml;base64,'],
|
||||
'html' => [QRCode::OUTPUT_MARKUP_HTML, '<div><span style="background:'],
|
||||
'text' => [QRCode::OUTPUT_STRING_TEXT, '⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕⭕'.PHP_EOL],
|
||||
'json' => [QRCode::OUTPUT_STRING_JSON, '[[18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18],'],
|
||||
|
||||
Reference in New Issue
Block a user