chillerlan / php-qrcode Goto Github PK
View Code? Open in Web Editor NEWA PHP QR Code generator and reader with a user-friendly API.
Home Page: https://smiley.codes/qrcode/
License: Apache License 2.0
A PHP QR Code generator and reader with a user-friendly API.
Home Page: https://smiley.codes/qrcode/
License: Apache License 2.0
With the official release of php 8, will we have support for it?
Currently adding it using composer fails:
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.
Problem 1
- Installation request for chillerlan/php-qrcode 3.3 -> satisfiable by chillerlan/php-qrcode[3.3.0].
- chillerlan/php-qrcode 3.3.0 requires php ^7.2 -> your PHP version (8.0.0) does not satisfy that requirement.
Regards,
When you have variable data length and want same size of inline svg image then it is better to have just viewbox defined. The only quick solution I have come up is ugly hack like this:
...
$output = $qr->render($data);
$output = preg_replace('~width="(\d+)px" height="(\d+)px"~', 'style="height: 100%; width: 100%" viewBox="0 0 $1 $2"', $output);
return $output;
Whats the reason for monopolizing the implementation with the composer? 'vendor', wheres Wally?
Unlike the announcement in the recent releases, the bug with the mask pattern generation was only partially fixed. What's worse is that several documentations, including ISO standards documents and Wikipedia, are divided about this specific topic. It turns out that the code was correct all the time and i fell for the (incorrect) ISO doc (p51), that has 2 parameters (i
& j
) swapped - i
as rows instead of columns and vice versa for j
. The repo where this library was forked from uses $col
for the rows, which wasn't much less confusing... Now swapping these 2 does only matter for the mask patterns 001, 010 and 100 which would end up rotated by 90ยฐ and therefore result in (mostly) unreadable codes.
The wrong rotated mask pattern 100 (left) and the expectation (right) and data "test" masked with the correct pattern 100 (below) [Version 10, ECC: L]
This has now (hopefully) (finally) been fixed and i promise i won't touch it again.
Another bug that seems to have existed ever since i've forked and refactored this repo is in the penalty calculation for the best mask pattern selection. It ranges from completely wrong results to off-by-one errors and needs further investigation (comparison to the original code, which i cannot confirm as correct due to the lack of tests).
Line 174 in fd679d1
Hi,
Thanks for the great lib :)
Everything works fine locally but doesn't seem to work on my server (Ubuntu 18.4 on Digital Ocean).
I have tried checking and installing the php7.3 extension one by one but still no success.
Can you help with a lead?
We've been using the example class QRImageWithText to add a text below the QR code. Because we will need to print the QR codes, we will probably need to switch from PNG to PDF so that it's in vectors. Is it possible to add a text in PDF just like we do it in PNG? If so, would it be possible to add some sample class?
Thanks for your great work!
I'm looking to generate QR codes from raw binary data rather than text, as it makes for much more compact codes - for example a timestamp value (from time()
) as text is at least 10 bytes, but as raw data is only 4 (pack('L', time())
), but this QR code renderer dies when given raw data like that. It it possible to disable character set semantics and accept raw binary input with this package?
Unable to install on my php v7.2.3 server due to php-settings-container dependency which seems to be locked at 2.0.0. Documentation claimed that this was usable with ^3.3 for PHP 7.2.x but this doesn't seem to be the case.
Exact error:
$ composer require chillerlan/php-qrcode:^3.3
Your requirements could not be resolved to an installable set of packages.
Problem 1
- chillerlan/php-settings-container 2.0.0 requires php ^7.4 -> your PHP version (7.2.33) does not satisfy that requirement.
- chillerlan/php-settings-container 2.0.0 requires php ^7.4 -> your PHP version (7.2.33) does not satisfy that requirement.
- Installation request for chillerlan/php-settings-container (locked at 2.0.0) -> satisfiable by chillerlan/php-settings-container[2.0.0].
I understand that you want to drop support for PHP 5.6 and even PHP7.
However, there's no technical reason for dropping 7.1 support. It should work perfectly fine on 7.1. There's a big difference between EOL and end of active support.
Otherwise this is a great library.
Hello,
maybe I am to stupid to find it out, but how can I change to qrcode from black to orange?
Thanks
Parse error: syntax error, unexpected 'SettingsContainerInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in C:\laragon\www\testeqrcode_php\vendor\chillerlan\php-qrcode\src\QRCode.php on line 153
Is it possible to add additional text to the QR image or under of the QR code?
I haven't found a way to store the image to a variable so I can base64encode it and store it at a database without writing it to filesystem...
Hi,
I've noticed that outputting the QR code as SVG generates SVG with lines that look like borders on some squares. I haven't managed to figure out what exactly those lines are, stroke, outline or just misalignment of paths, it seems like they are transparent. Here is a screenshot of SVG versus the PNG output so its easier to notice what I'm talking about.
My QR options are:
_
'version' => 6,
'eccLevel' => QRCode::ECC_L,
'outputType' => QRCode::OUTPUT_MARKUP_SVG,
'imageBase64' => false
_
Can you try recreating the issue and looking into it please, maybe I'm doing something wrong. Thank you ahead!
as the title says, Does the lib have this settings?
Is there easy way to convert rectangles or squares to circles, or can you point me how can I do that?
Error i get is [portlandia_screaming.gif] instead of actual image!
Line 51 in fd679d1
It return the image black and white and not with colors as shown in examples
$options = new QRCodeLogoOptions;
$options->version = 5;
$options->eccLevel = QRCode::ECC_H;
$options->imageBase64 = false;
$options->logoSpaceWidth = 13;
$options->logoSpaceHeight = 13;
$options->scale = 5;
$options->imageTransparent = false;
$options2 = new QROptions([
'version' => 7,
'outputType' => QRCode::OUTPUT_IMAGICK,
'eccLevel' => QRCode::ECC_H,
'scale' => 5,
'moduleValues' => [
// finder
1536 => '#A71111', // dark (true)
6 => '#FFBFBF', // light (false)
// alignment
2560 => '#A70364',
10 => '#FFC9C9',
// timing
3072 => '#98005D',
12 => '#FFB8E9',
// format
3584 => '#003804',
14 => '#00FB12',
// version
4096 => '#650098',
16 => '#E0B8FF',
// data
1024 => '#4A6000',
4 => '#ECF9BE',
// darkmodule
512 => '#080063',
// separator
8 => '#DDDDDD',
// quietzone
18 => '#DDDDDD',
],
]);
header('Content-type: image/png');
// print_r((new QRCode($options2))->render($data));die();
$qrOutputInterface = new QRCodeLogo($options, (new QRCode($options2))->getMatrix($data));
echo $qrOutputInterface->dump(null, FCPATH.'/image.png');
die();
First off, thank you very much for this library!
I'm working with the Drupal 8 GA Login module and we're hoping to use this library. We have the 2.x branch of this library working well, but had a user run into a problem with the minimum php version being 7.x.
Since Drupal 8 still officially supports PHP 5.6 I think it's in the GA_Login module's best interest to do the same, so I'm curious what you can tell me about the last version of this library that supported php5.6.
It looks like to me that we could use version 1.1.0 from packagist and support php5.6. Does that sound right to you?
If 1.1.0 branch would work for us, do you think there is any reason why we (GA_Login module) shouldn't use it? Is it significantly behind in features we might need, or insecure in some way?
Thanks again for dropping by the ga_login issue queue and for the great library!
The latest release is restricted to ^7.4
. Is there anything stopping this from being bumped?
Parse error: syntax error, unexpected 'SettingsContainerInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in C:\laragon\www\testeqrcode_php\vendor\chillerlan\php-qrcode\src\QRCode.php on line 153
Hello,
Thank you for the well done QR Code generation!
I see that there is a configuration option that supports a logo in the center of the QR Code, which has not yet been implemented. Is there a target time frame for this, or is there insufficient user interest?
Best Regards,
Edward
$ phpunit
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.
Cannot open file "/Users/luxin88/Documents/github/php-qrcode/vendor/autoload.php".
Hi,
is it possible to use a custom image like a logo or anything else and have it as an overlay? If it is possible, it would be great if you could provide an example.
Something like this one: https://stackoverflow.com/questions/45520988/creating-a-qr-code-with-a-centered-logo-in-php-with-php-qr-code-generator or this one
https://ourcodeworld.com/articles/read/225/how-to-generate-qr-code-with-logo-easily-in-php-automatically
Thank you very much!
Best
Alexander
chillerlan\Traits\TraitException: ClassLoader: code length overflow. (1596 > 1248bit)
...
Hey,
is it possible to generate a QR-Code with a white background?
At the moment all have transparent background and when display in an email with enabled dark-mode, it is almost impossible to even see the qr-code (Outlook for Android).
Thank you, Louis
Hey there,
after upgrading to 3.4.0, the QR Code for SVG changed by default to base64
.
Not sure if thats a BC break in 4.x aswell.
Would love if this is being fixed somehow.
Thanks in advance.
Hello,
In regards to #35 (where you did an EXCELLENT job - as in the full library as a whole), I have noticed that using non-square logos it's a bit hard to determine the number of squares that should be reserved in the matrix for a particular image using logoWidth and logoHeight in a way it doesn't stretch.
Example given: I have a logo of 972x324px (3:1 width:height scale). Setting logoWidth = 30 and logoHeight = 10 (following the 3:1 WxH ratio of the logo), the resulting QR Code is "stretched" horizontally... ๐น
Reason: there's 1 extra "block" reserved by your lib at all edges (top, bottom, left, right) and the actual space the logo will occupy in the matrix is 28x8 (3.5:1).
For it to work as expected, I had to set logoWidth = 32 (2 blocks extra at top and bottom = 30 for the logo image) and logoHeight = 12 (2 blocks extra at left and right = 10 for the logo), and boom! The logo is now perfectly fit and the ratio 3:1 is kept.
My suggestion is logoWidth and logoHeight had 2 "automatically added" internally in the lib, so the definition of these values would be much more intuitive (W 30 H 10 = ratio kept).
First of all: awesome package, well done. ๐
I saw a little mention of logo support in the documentation, but that it wasn't implemented yet. Any idea when this will be available?
In the implement of this class in a controller of laravel i have this:
app/Http/Controllers/TestCodeQRController.php
<?php
// namespace App\Http\Controllers;
namespace chillerlan\QRCode;
use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
class TestCodeQRController extends Controller
{
function index():string
{
echo 'Testing code QR()';
$data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
echo '<img src="'.(new QRCode)->render($data).'" />';
return '';
}
}
and the error is:
Class 'chillerlan\QRCode\Controller' not found
Can you help me ? Thanks a lot!
The QR Code types and RS blocks were hardcoded for types up to 10, most methods support up to type 40.
http://www.qrcode.com/en/about/version.html
todo: remove hardcoding hardcode better.
QR codes generated with the same parameters in v.1.0.3 and up do not seem to scan correctly. Using v.1.0.2 the code scans perfectly. This is using examples/image.php.
Hi,
I have problem with generating SVG QRCode. No matter which size I'm gettting QRCodeException
Here is my content. It is valid QRCode content for Czech standart for QR Invoice (http://qr-faktura.cz/).
Please could you increase MAX_BITS
or provide option to bypase?
SPD*1.0*ACC:CZ8620100000002000948394*AM:3025.00*CC:CZK*X-VS:1181273*X-SS:0*X-KS:308*MSG:1181273*DT:20190318*X-INV:SID%2A1.0%2ATB0%3A2500.00%2AT0%3A525.00%2AID%3A1181273%2ADD%3A20190304%2AINI%3A25520270%2AVII%3ACZ25520270%2AINR%3A24791334%2AVIR%3ACZ24791334%2ADUZP%3A20190304%2AAM%3A3025.00%2AVS%3A1181273%2ADT%3A20190318%2ACC%3ACZK%2AX-SW%3Acpilot.cz*
require_once '../vendor/autoload.php';
The file ../vendor/autoload.php
is missing.
Hi! This is probably a very noob question to ask but how do I save the QR code to my server folder? I've been using the QR library which this was based on but there you would call QRcode::png($data, $filePath . $fileName, QR_ECLEVEL_H, 6, 1);
and it would be saved.
I do not want to display or output anything.
I am sure there is a way, but I cannot easily see it in the documentation or the examples.
-FT
I have done:
step 1: get composer
step 2: composer install (created all dirs etc)
What do I do now to run the example(s) in the tests directory?
Could someone provide a simple index.php that would use the package, and is located in the root dir of my server? The package is installed in php-qrcode-master directory, under the root dir.
Thanks very much.
Hello,
is it possible to generate output image with fixed width & height no matter how long data is?
Thanks for the work.
We think about creating a PDF output module for this library but I'm not sure if we should keep it as an external repository/module or if you are willed to accept a PR for a default implementation?
We would use FPDF under the hood and the QR codes will be created as simple vector based PDF files. I'm also not sure if (in case for a default implementation) the dependency to FPDF should be hard (in the composer.json) or optional.
The class name for a default implementation would be chillerlan\QRCode\Output\QRFpdf
.
If the created QR codes needs to be reused in dynamic created PDFs they can be reimported by FPDI.
What do you think? Separate repository/module or default implementation? :-)
Hello,
Based on the example taken on php-qrcode/examples/image.php
If i take the exact same example you wrote : working.
If i just remove the content form moduleValues and put an eccLevel to ECC_H : working.
But i get a code length overflow with the following string of data :
$data = 'otpauth://totp/flupflup.com:marco?secret=II6SXEVSTAQV4SNJ&issuer=flupflup.com';
$options = new QROptions([
'version' => 7,
'outputType' => QRCode::OUTPUT_IMAGE_PNG,
'eccLevel' => QRCode::ECC_H,
'scale' => 5,
'imageBase64' => false,
'moduleValues' => [],
]);
header('Content-type: image/png');
echo (new QRCode($options))->render($data);
It looks like it happen only with ECC_H and the other are working well.
I don't really know if my error is relevant or if I did something wrong. But it might be useful to share.
Here the stacktrace :
Stack trace:
#0 /public_html/vendor/chillerlan/php-qrcode/src/Data/QRDataAbstract.php(118): chillerlan\QRCode\Data\QRDataAbstract->writeBitBuffer('otpauth://totp/...')
#1 /public_html/vendor/chillerlan/php-qrcode/src/Data/QRDataAbstract.php(95): chillerlan\QRCode\Data\QRDataAbstract->setData('otpauth://totp/...')
#2 /public_html/vendor/chillerlan/php-qrcode/src/QRCode.php(205): chillerlan\QRCode\Data\QRDataAbstract->__construct(Object(chillerlan\QRCode\QROptions), 'otpauth://totp/...')
#3 /public_html/vendor/chillerlan/php-qrcode/src/QRCode.php(157): chillerlan\QRCode\QRCode->initDataInterface('otpauth://totp/...')
#4 /public_html/vendor/chillerlan/php-qrcode/src/QRCode.php(230): chillerlan\QRCode\QRCode->getMatrix('otpauth://totp/...')
#5 /public_html/vendor/chillerlan/php-qrcode/src/Data/QRDataAbstract.php on line 230
Anyway, thank's for the tools, you've made a neat job.
When trying to save the QRCode image in the database (POSTGRES) it generates the error:
Fatal error: Uncaught Error: Class 'chillerlan \ QRCodeExamples \ Bank' not found in C: \ xampp \ htdocs \ testeQRcode \ cadEvento.php: 29 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ testQRcode \ cadEvento.php on line 29
I wonder if the library supports PostgresSQL
Using WKHTML2PDF does not render the SVG at all. It comes up blank.
This is due to the extra % in the svgHeader string:
protected string $svgHeader = '<svg xmlns="http://www.w3.org/2000/svg" class="qr-svg %1$s" '.
'style="width: 100%**%**; height: auto;" viewBox="0 0 %2$d %2$d">';
first: thank you for this excellent script!
is there a function to get the qr-version of the generated qr-code when in options "version" is set to QRCode::VERSION_AUTO ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.