mirror of
https://github.com/chillerlan/php-qrcode.git
synced 2026-10-22 03:35:45 +00:00
:octocat: rename QROptionsTrait::$imageBase64 to $outputBase64, deprecate old name and redirect calls
This commit is contained in:
@@ -39,7 +39,7 @@ Inherited from [`SettingsContainerAbstract`](https://github.com/chillerlan/php-s
|
||||
| `$outputInterface` | `string\|null` | `null` | * | The FQCN of the custom `QROutputInterface` if `QROptions::$outputType` is set to `QROutputInterface::CUSTOM` |
|
||||
| `$returnResource` | `bool` | `false` | * | Return the image resource instead of a render if applicable. |
|
||||
| `$cachefile` | `string\|null` | `null` | * | Optional cache file path |
|
||||
| `$imageBase64` | `bool` | `true` | * | Toggle base64 or raw image data (if applicable) |
|
||||
| `$outputBase64` | `bool` | `true` | * | Toggle base64 data URI or raw data output (if applicable) |
|
||||
| `$eol` | `string` | `PHP_EOL` | * | Newline string (HTML, SVG, TEXT) |
|
||||
| `$bgColor` | `mixed` | `null` | a valid FPDF, GD or Imagick color value | Sets the image background color (if applicable). QRImagick: defaults to "white", QRGdImage: defaults to [255, 255, 255], QRFpdf: defaults to blank internally (white page) |
|
||||
| `$drawLightModules` | `bool` | `true` | * | Whether to draw the light (false) modules |
|
||||
|
||||
@@ -126,8 +126,8 @@ $qrcode->setOptions($options);
|
||||
Save the QR Code output to `/path/to/qrcode.svg`:
|
||||
|
||||
```php
|
||||
$options->imageBase64 = false;
|
||||
$options->cachefile = '/path/to/qrcode.svg';
|
||||
$options->outputBase64 = false;
|
||||
$options->cachefile = '/path/to/qrcode.svg';
|
||||
|
||||
$qrcode->render($data);
|
||||
```
|
||||
|
||||
@@ -27,8 +27,8 @@ Configuration using `QROptions`:
|
||||
|
||||
```php
|
||||
$options = new QROptions;
|
||||
$options->version = 7;
|
||||
$options->imageBase64 = false; // output raw image instead of base64 data URI
|
||||
$options->version = 7;
|
||||
$options->outputBase64 = false; // output raw image instead of base64 data URI
|
||||
|
||||
header('Content-type: image/svg+xml'); // the image type is SVG by default
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ $options->algorithm = AuthenticatorInterface::ALGO_SHA512;
|
||||
*/
|
||||
$options->version = 7;
|
||||
$options->addQuietzone = false;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->svgAddXmlHeader = false;
|
||||
$options->cssClass = 'my-qrcode';
|
||||
$options->drawLightModules = false;
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ $options->scale = 5;
|
||||
$options->fpdfMeasureUnit = 'mm';
|
||||
$options->bgColor = [222, 222, 222];
|
||||
$options->drawLightModules = false;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->moduleValues = [
|
||||
// finder
|
||||
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ $options = new QROptions;
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::GDIMAGE_PNG;
|
||||
$options->scale = 20;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->bgColor = [200, 150, 200];
|
||||
$options->imageTransparent = true;
|
||||
#$options->transparencyColor = [233, 233, 233];
|
||||
|
||||
@@ -63,7 +63,7 @@ class QRImageWithLogo extends QRGdImage{
|
||||
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ class QRImageWithLogo extends QRGdImage{
|
||||
$options = new QROptions;
|
||||
|
||||
$options->version = 5;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->scale = 6;
|
||||
$options->imageTransparent = false;
|
||||
$options->drawCircularModules = true;
|
||||
|
||||
@@ -42,7 +42,7 @@ class QRImageWithText extends QRGdImage{
|
||||
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
@@ -96,10 +96,10 @@ class QRImageWithText extends QRGdImage{
|
||||
|
||||
$options = new QROptions;
|
||||
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::GDIMAGE_PNG;
|
||||
$options->scale = 3;
|
||||
$options->imageBase64 = false;
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::GDIMAGE_PNG;
|
||||
$options->scale = 3;
|
||||
$options->outputBase64 = false;
|
||||
|
||||
|
||||
$qrcode = new QRCode($options);
|
||||
|
||||
@@ -19,7 +19,7 @@ $options = new QROptions;
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::IMAGICK;
|
||||
$options->scale = 20;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->bgColor = '#ccccaa';
|
||||
$options->imageTransparent = true;
|
||||
#$options->transparencyColor = '#ECF9BE';
|
||||
|
||||
@@ -54,7 +54,7 @@ class QRImagickWithLogo extends QRImagick{
|
||||
$this->imagick->destroy();
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData));
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ $options->version = 5;
|
||||
$options->outputType = QROutputInterface::CUSTOM;
|
||||
$options->outputInterface = QRImagickWithLogo::class; // use the custom output class
|
||||
$options->eccLevel = EccLevel::H;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->addLogoSpace = true;
|
||||
$options->logoSpaceWidth = 15;
|
||||
$options->logoSpaceHeight = 15;
|
||||
|
||||
@@ -19,7 +19,7 @@ mb_internal_encoding('UTF-8');
|
||||
|
||||
// please excuse the IDE yelling https://youtrack.jetbrains.com/issue/WI-66549
|
||||
$options = new QROptions;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->connectPaths = true;
|
||||
|
||||
$qrcode = (new QRCode($options))
|
||||
|
||||
@@ -67,7 +67,7 @@ try{
|
||||
'moduleValues' => $moduleValues,
|
||||
'outputType' => $_POST['output_type'],
|
||||
'scale' => (int)$_POST['scale'],
|
||||
'imageBase64' => true,
|
||||
'outputBase64' => true,
|
||||
'imageTransparent' => false,
|
||||
]);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ require_once __DIR__.'/../vendor/autoload.php';
|
||||
$options = new QROptions;
|
||||
|
||||
$options->outputType = QROutputInterface::MARKUP_SVG;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->svgAddXmlHeader = false;
|
||||
$options->connectPaths = true;
|
||||
$options->drawCircularModules = false;
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ $options = new QROptions;
|
||||
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::MARKUP_SVG;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
// if set to false, the light modules won't be rendered
|
||||
$options->drawLightModules = true;
|
||||
// empty the default value to remove the fill* and opacity* attributes from the <path> elements
|
||||
|
||||
@@ -256,7 +256,7 @@ $options->meltRadius = 0.4;
|
||||
$options->version = 7;
|
||||
$options->outputType = QROutputInterface::CUSTOM;
|
||||
$options->outputInterface = MeltedSVGQRCodeOutput::class;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->addQuietzone = true;
|
||||
$options->eccLevel = EccLevel::H;
|
||||
$options->addLogoSpace = true;
|
||||
|
||||
@@ -135,7 +135,7 @@ $options->outputInterface = RandomDotsSVGOutput::class;
|
||||
$options->version = 5;
|
||||
$options->eccLevel = EccLevel::H;
|
||||
$options->addQuietzone = true;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->drawLightModules = false;
|
||||
$options->connectPaths = true;
|
||||
$options->excludeFromConnect = [
|
||||
|
||||
@@ -65,7 +65,7 @@ class RoundQuietzoneSVGoutput extends QRMarkupSVG{
|
||||
$svg .= sprintf('%1$s</svg>%1$s', $this->options->eol);
|
||||
|
||||
// transform to data URI only when not saving to file
|
||||
if(!$saveToFile && $this->options->imageBase64){
|
||||
if(!$saveToFile && $this->options->outputBase64){
|
||||
$svg = $this->toBase64DataURI($svg, 'image/svg+xml');
|
||||
}
|
||||
|
||||
@@ -325,7 +325,7 @@ $options->svgLogoCssClass = 'logo';
|
||||
$options->version = 7;
|
||||
$options->eccLevel = EccLevel::H;
|
||||
$options->addQuietzone = false; // we're not adding a quiet zone, this is done internally in our own module
|
||||
$options->imageBase64 = false; // avoid base64 URI output for the example
|
||||
$options->outputBase64 = false; // avoid base64 URI output for the example
|
||||
$options->outputType = QROutputInterface::CUSTOM;
|
||||
$options->outputInterface = RoundQuietzoneSVGoutput::class; // load our own output class
|
||||
$options->drawLightModules = false; // set to true to add the light modules
|
||||
|
||||
@@ -115,7 +115,7 @@ $options->svgLogoCssClass = 'dark';
|
||||
$options->version = 5;
|
||||
$options->outputType = QROutputInterface::CUSTOM;
|
||||
$options->outputInterface = QRSvgWithLogo::class;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->eccLevel = EccLevel::H; // ECC level H is necessary when using logos
|
||||
$options->addQuietzone = true;
|
||||
$options->drawLightModules = true;
|
||||
|
||||
@@ -171,7 +171,7 @@ $options->version = 5;
|
||||
$options->quietzoneSize = 4;
|
||||
$options->outputType = QROutputInterface::CUSTOM;
|
||||
$options->outputInterface = QRSvgWithLogoAndCustomShapes::class;
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->eccLevel = EccLevel::H; // ECC level H is required when using logos
|
||||
$options->addQuietzone = true;
|
||||
|
||||
|
||||
@@ -143,7 +143,7 @@ class QRFpdf extends QROutputAbstract{
|
||||
|
||||
$this->saveToFile($pdfData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$pdfData = $this->toBase64DataURI($pdfData, 'application/pdf');
|
||||
}
|
||||
|
||||
|
||||
@@ -179,7 +179,7 @@ class QRGdImage extends QROutputAbstract{
|
||||
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, 'image/'.$this->options->outputType);
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class QRImagick extends QROutputAbstract{
|
||||
|
||||
$this->saveToFile($imageData, $file);
|
||||
|
||||
if($this->options->imageBase64){
|
||||
if($this->options->outputBase64){
|
||||
$imageData = $this->toBase64DataURI($imageData, (new finfo(FILEINFO_MIME_TYPE))->buffer($imageData));
|
||||
}
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ class QRMarkupSVG extends QRMarkup{
|
||||
$svg .= sprintf('%1$s</svg>%1$s', $this->options->eol);
|
||||
|
||||
// transform to data URI only when not saving to file
|
||||
if(!$saveToFile && $this->options->imageBase64){
|
||||
if(!$saveToFile && $this->options->outputBase64){
|
||||
$svg = $this->toBase64DataURI($svg, 'image/svg+xml');
|
||||
}
|
||||
|
||||
|
||||
+28
-2
@@ -105,7 +105,7 @@ trait QROptionsTrait{
|
||||
|
||||
/**
|
||||
* Return the image resource instead of a render if applicable.
|
||||
* This option overrides other output options, such as $cachefile and $imageBase64.
|
||||
* This option overrides/ignores other output options, such as $cachefile and $outputBase64.
|
||||
*
|
||||
* Supported by the following modules:
|
||||
*
|
||||
@@ -127,10 +127,16 @@ trait QROptionsTrait{
|
||||
protected ?string $cachefile = null;
|
||||
|
||||
/**
|
||||
* Toggle base64 or raw image data (if applicable)
|
||||
* @deprecated 5.0.0 use QROptions::$outputBase64 instead
|
||||
* @see \chillerlan\QRCode\QROptions::$outputBase64
|
||||
*/
|
||||
protected bool $imageBase64 = true;
|
||||
|
||||
/**
|
||||
* Toggle base64 data URI or raw data output (if applicable)
|
||||
*/
|
||||
protected bool $outputBase64 = true;
|
||||
|
||||
/**
|
||||
* Newline string
|
||||
*/
|
||||
@@ -530,4 +536,24 @@ trait QROptionsTrait{
|
||||
$this->circleRadius = max(0.1, min(0.75, $circleRadius));
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect call to the new variable
|
||||
*
|
||||
* @deprecated 5.0.0 use QROptions::$outputBase64 instead
|
||||
* @see \chillerlan\QRCode\QROptions::$outputBase64
|
||||
*/
|
||||
protected function set_imageBase64(bool $imageBase64):void{
|
||||
$this->outputBase64 = $imageBase64;
|
||||
}
|
||||
|
||||
/**
|
||||
* redirect call to the new variable
|
||||
*
|
||||
* @deprecated 5.0.0 use QROptions::$outputBase64 instead
|
||||
* @see \chillerlan\QRCode\QROptions::$outputBase64
|
||||
*/
|
||||
protected function get_imageBase64():bool{
|
||||
return $this->outputBase64;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ final class QRDataTest extends TestCase{
|
||||
$this::assertSame(3, $matrix->getVersion()->getVersionNumber());
|
||||
|
||||
// attempt to read
|
||||
$options->imageBase64 = false;
|
||||
$options->outputBase64 = false;
|
||||
$options->readerUseImagickIfAvailable = false;
|
||||
|
||||
$output = new QRGdImage($options, $matrix);
|
||||
|
||||
@@ -43,7 +43,7 @@ abstract class QRMarkupTestAbstract extends QROutputTestAbstract{
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function testSetModuleValues():void{
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->outputBase64 = false;
|
||||
$this->options->drawLightModules = true;
|
||||
$this->options->moduleValues = [
|
||||
// data
|
||||
|
||||
@@ -91,8 +91,8 @@ abstract class QROutputTestAbstract extends TestCase{
|
||||
* coverage of the built-in output modules
|
||||
*/
|
||||
public function testRenderToCacheFile():void{
|
||||
$this->options->imageBase64 = false;
|
||||
$this->outputInterface = new $this->FQN($this->options, $this->matrix);
|
||||
$this->options->outputBase64 = false;
|
||||
$this->outputInterface = new $this->FQN($this->options, $this->matrix);
|
||||
// create the cache file
|
||||
$file = $this->builddir.'/test.output.'.$this->type;
|
||||
$data = $this->outputInterface->dump($file);
|
||||
|
||||
@@ -96,8 +96,8 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
|
||||
}
|
||||
|
||||
public function testReaderMultiMode():void{
|
||||
$this->options->outputType = QROutputInterface::GDIMAGE_PNG;
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->outputType = QROutputInterface::GDIMAGE_PNG;
|
||||
$this->options->outputBase64 = false;
|
||||
|
||||
$numeric = '123456789012345678901234567890';
|
||||
$alphanum = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 $%*+-./:';
|
||||
@@ -149,7 +149,7 @@ abstract class QRCodeReaderTestAbstract extends TestCase{
|
||||
$this->options->imageTransparent = false;
|
||||
$this->options->eccLevel = $ecc->getLevel();
|
||||
$this->options->version = $version->getVersionNumber();
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->outputBase64 = false;
|
||||
// what's interesting is that a smaller scale seems to produce fewer reader errors???
|
||||
// usually from version 20 up, independend of the luminance source
|
||||
// scale 1-2 produces none, scale 3: 1 error, scale 4: 6 errors, scale 5: 5 errors, scale 10: 10 errors
|
||||
|
||||
@@ -86,8 +86,8 @@ final class QRCodeTest extends TestCase{
|
||||
* Tests if a cache file is properly saved in the given path
|
||||
*/
|
||||
public function testRenderToCacheFile():void{
|
||||
$this->options->cachefile = $this->builddir.'/test.cache.svg';
|
||||
$this->options->imageBase64 = false;
|
||||
$this->options->cachefile = $this->builddir.'/test.cache.svg';
|
||||
$this->options->outputBase64 = false;
|
||||
// create the cache file
|
||||
$data = $this->qrcode->setOptions($this->options)->render('test');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user