mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-09-05 23:18:20 +00:00
:octocat: simplify base64 URI creation
This commit is contained in:
@@ -72,7 +72,7 @@ class QRImageWithLogo extends QRImage{
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
|
||||
$imageData = $this->base64encode($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace chillerlan\QRCodeExamples;
|
||||
|
||||
use chillerlan\QRCode\Output\QRImage;
|
||||
|
||||
use function base64_encode, imagechar, imagecolorallocate, imagecolortransparent, imagecopymerge, imagecreatetruecolor,
|
||||
use function imagechar, imagecolorallocate, imagecolortransparent, imagecopymerge, imagecreatetruecolor,
|
||||
imagedestroy, imagefilledrectangle, imagefontwidth, in_array, round, str_split, strlen;
|
||||
|
||||
class QRImageWithText extends QRImage{
|
||||
@@ -50,7 +50,7 @@ class QRImageWithText extends QRImage{
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$imageData = 'data:image/'.$this->options->outputType.';base64,'.base64_encode($imageData);
|
||||
$imageData = $this->base64encode($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
|
||||
@@ -103,7 +103,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$pdfData = sprintf('data:application/pdf;base64,%s', base64_encode($pdfData));
|
||||
$pdfData = $this->base64encode($pdfData, 'application/pdf');
|
||||
}
|
||||
|
||||
return $pdfData;
|
||||
|
||||
@@ -19,9 +19,9 @@ use chillerlan\QRCode\{QRCode, QRCodeException};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
use Exception;
|
||||
|
||||
use function array_values, base64_encode, call_user_func, count, extension_loaded, imagecolorallocate, imagecolortransparent,
|
||||
use function array_values, call_user_func, count, extension_loaded, imagecolorallocate, imagecolortransparent,
|
||||
imagecreatetruecolor, imagedestroy, imagefilledrectangle, imagegif, imagejpeg, imagepng, in_array,
|
||||
is_array, ob_end_clean, ob_get_contents, ob_start, range, sprintf;
|
||||
is_array, ob_end_clean, ob_get_contents, ob_start, range;
|
||||
|
||||
/**
|
||||
* Converts the matrix into GD images, raw or base64 output (requires ext-gd)
|
||||
@@ -127,7 +127,7 @@ class QRImage extends QROutputAbstract{
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$imageData = sprintf('data:image/%s;base64,%s', $this->options->outputType, base64_encode($imageData));
|
||||
$imageData = $this->base64encode($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
return $imageData;
|
||||
|
||||
@@ -151,7 +151,7 @@ class QRMarkup extends QROutputAbstract{
|
||||
}
|
||||
|
||||
if($this->options->imageBase64){
|
||||
$svg = sprintf('data:image/svg+xml;base64,%s', base64_encode($svg));
|
||||
$svg = $this->base64encode($svg, 'image/svg+xml');
|
||||
}
|
||||
|
||||
return $svg;
|
||||
|
||||
@@ -14,8 +14,7 @@ namespace chillerlan\QRCode\Output;
|
||||
|
||||
use chillerlan\QRCode\{Data\QRMatrix, QRCode};
|
||||
use chillerlan\Settings\SettingsContainerInterface;
|
||||
|
||||
use function call_user_func_array, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf;
|
||||
use function base64_encode, call_user_func_array, dirname, file_put_contents, get_called_class, in_array, is_writable, sprintf;
|
||||
|
||||
/**
|
||||
* common output abstract
|
||||
@@ -92,6 +91,13 @@ abstract class QROutputAbstract implements QROutputInterface{
|
||||
*/
|
||||
abstract protected function setModuleValues():void;
|
||||
|
||||
/**
|
||||
* Returns a base64 data URI for the given string and mime type
|
||||
*/
|
||||
protected function base64encode(string $data, string $mime):string{
|
||||
return sprintf('data:%s;base64,%s', $mime, base64_encode($data));
|
||||
}
|
||||
|
||||
/**
|
||||
* saves the qr data to a file
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user