Help saving in correct format #280
-
HI, found out recently about this tool and trying it out to see how it works. Thing is, I don't understand how to save locally my generated qr code as a png. <?php
declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use chillerlan\QRCode\{QRCode, QROptions};
use chillerlan\QRCode\Data\QRMatrix;
use chillerlan\QRCode\Output\QRGdImagePNG;
$options = new QROptions;
$options->version = 7;
$options->outputInterface = QRGdImagePNG::class;
$options->scale = 20;
$options->outputBase64 = false;
$options->bgColor = [200, 150, 200];
$options->imageTransparent = true;
#$options->transparencyColor = [233, 233, 233];
$options->drawCircularModules = false;
$options->drawLightModules = true;
$options->circleRadius = 0.4;
$options->keepAsSquare = [
QRMatrix::M_FINDER_DARK,
QRMatrix::M_FINDER_DOT,
QRMatrix::M_ALIGNMENT_DARK,
];
$options->moduleValues = [
// finder
QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
QRMatrix::M_FINDER => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
// alignment
QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
QRMatrix::M_ALIGNMENT => [233, 233, 233],
// timing
QRMatrix::M_TIMING_DARK => [255, 0, 0],
QRMatrix::M_TIMING => [233, 233, 233],
// format
QRMatrix::M_FORMAT_DARK => [67, 159, 84],
QRMatrix::M_FORMAT => [233, 233, 233],
// version
QRMatrix::M_VERSION_DARK => [62, 174, 190],
QRMatrix::M_VERSION => [233, 233, 233],
// data
QRMatrix::M_DATA_DARK => [0, 0, 0],
QRMatrix::M_DATA => [233, 233, 233],
// darkmodule
QRMatrix::M_DARKMODULE => [0, 0, 0],
// separator
QRMatrix::M_SEPARATOR => [233, 233, 233],
// quietzone
QRMatrix::M_QUIETZONE => [233, 233, 233],
// logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
QRMatrix::M_LOGO => [233, 233, 233],
];
$data = 'https://dfstudio-d420.kxcdn.com/wordpress/wp-content/uploads/2019/06/digital_camera_photo-980x653.jpg';
$qrcode = (new QRCode($options))->render($data, __DIR__.'/qrOutput/qrCode.svg');
// default output is a base64 encoded data URI
printf('<img src="%s" alt="QR Code" />', $qrcode); With that I'm able to both show the generated qr code, and save it locally. The problem is that it saves it as a svg, not a png (jpeg would be fine too). Already tried changing the extension in the render() but the output is a corrupted file. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
The example as you posted it here would save a PNG file, however, there's a |
Beta Was this translation helpful? Give feedback.
If it is still saved as SVG, this means it is using the SVG output class, which is the default output. And just now I realize that you might be using an example from
dev-main
with one of the v5.x releases. Indev-main
(v6) the optionoutputType
has been removed (see #223). You will need to add this setting and it should work fine:(you could also use one of the several constants that v5 provides for the several built-in output classes, but for simpler migration to future versions i wouldn't recommend this anymore)
See also https://github.com/chillerlan/php-qrcode?tab=readme-ov-file#documentation