Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for logo? #52

Closed
EdwardCaulfield opened this issue Sep 25, 2020 · 15 comments
Closed

Support for logo? #52

EdwardCaulfield opened this issue Sep 25, 2020 · 15 comments

Comments

@EdwardCaulfield
Copy link

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

@codemasher
Copy link
Member

Hi, i haven't looked into implementing it since it's a feature that's mostly used commercially (and was only requested by few yet). One could submit a pull request or donate a bit though.

@renatofrota
Copy link

renatofrota commented Nov 15, 2020

Hi, i haven't looked into implementing it since it's a feature that's mostly used commercially (and was only requested by few yet). One could submit a pull request or donate a bit though.

@codemasher

I am interested in buying/financing a PHP (preferable) or JS QR Code generator with abilities your current one has and some features present in this generator added, namely:

  • embedding text (default effect only (stroke))
  • embedding image
  • anchor pattern selection (mainly the ability to use circle anchors)
  • modify the anchor colors separately (the "frame" and the "point")

Please give me a quote to have these features added to your existing code (it may be released as a new open source version, of course 😉).

Thanks.

@codemasher
Copy link
Member

Hi! First off: I'm a private person maintaining this library in their free time, therefore i cannot give you a quote (or even issue invoices); what I can do is estimating the required work time and you can donate whatever my time is worth to you.

A bit of research (and the example you provided) has shown that a lot of QR Codes with logos are created by just slapping the logo over the generated image. I'm still unsure whether to add this as a feature as it is something that can easily implemented by extending the library as shown in the examples (#35 is very similar). I'm down to adding an option to create a blank space in the QR Matrix, where then text or a logo image can be added.
The same goes for the finder patterns - i could make it so that they're left blank and an optional image can be added.
All of this would be done in the GD and/or Imagemagick output modules. SVG/HTML output would add another layer of complexity I wouldn't want to deal with (the example you provided doesn't seem to render the logo/text/finders in SVG either).

Cheers!

@renatofrota
Copy link

I have managed to add a logo at the center after sending my message above. Indeed this is not hard.

The same goes for the finder patterns - i could make it so that they're left blank and an optional image can be added.

The size of the finders do vary depending on the resulting QR Code version (size). So this is not that easy currently.

How much time you think you would need to invest in order to add this feature in a way I could pass the image I want to use as finder and the library automatically [re]size and place it at the corners?

Or, how much time you think you would need to invest in order to provide the ability to set different colors for the finder's "frame" and "point" (and maybe the same for the alignment squares)? They currently have the same color for both frame and the point inside and having them in different colors would be enough to the personalization (and maybe this is easier to code than the other modification proposed above, considering the color customization is an existing feature).

@codemasher
Copy link
Member

Adding another M_* type for the inner part (or outer, respectively) of the finder is what i also had in mind - this would be the easiest to fit in seamless and also be compatible with SVG output (1hr).
Clearing the finder patterns and adding/scaling/flipping images to replace them isn't too hard either but requires some extra settings and extending the aforementioned example code (2-3hr).
As a bonus I'd add a method to QRMatrix which clears an area of a given size for a logo or text - M_LOGO is outcommented in the code since forever. If your're looking for more customization, check out #23.

@renatofrota
Copy link

Adding another M_* type for the inner part (or outer, respectively) of the finder is what i also had in mind - this would be the easiest to fit in seamless and also be compatible with SVG output (1hr).

and

As a bonus I'd add a method to QRMatrix which clears an area of a given size for a logo or text - M_LOGO is outcommented in the code since forever.

These changes are enough for me, personally. It would be nice to have an option to add a small margin to the embedded logo so it doesn't "snap" to the squares of the QRMatrix.

If you have a bitcoin address, let me know. Otherwise, I will donate through the PayPal button.

@codemasher
Copy link
Member

It would be nice to have an option to add a small margin to the embedded logo so it doesn't "snap" to the squares of the QRMatrix.

Yes, that's the intend of the logo area.

I don't use Bitcoin - PayPal is perfectly fine. Thanks in advance!

@renatofrota
Copy link

I have made a small donation. Your currency is much more valuable than mine, unfortunately. So I will understand if you prefer to wait for more donation$ to come before starting these changes.

Thank you for your attention.

@codemasher
Copy link
Member

codemasher commented Nov 15, 2020

Ok, so this is where we're at:
QR1
Please note that the QR Code might become unreadable despite staying below the maximum error correction capacity - you might want to test readability on several samples.
To add a logo space, you can call $this->matrix->setLogoSpace($width, $height); in an output module that implements a QROutputInterface by extending QROutputAbstract or one of its inheritors. You can even color it in the same way than other parts of the matrix. The same goes for the inner (dot) part of the finder patterns.

@renatofrota
Copy link

Awesome job! Thank you very much.

This sample in particular is a bit harder to read but it is probably too close the ECC limit. I would use a smaller reserved space - as I did manually on some QR Codes so far and I didn't face issues reading them.

BTW, you've said "where we're at", so will you add a function to render the logo itself in the "LogoSpace"? Just asking so I do not end up spending time on it unnecessarily.

@codemasher
Copy link
Member

codemasher commented Nov 16, 2020

Happy to help!

This sample in particular is a bit harder to read but it is probably too close the ECC limit.

Yes, i was trying out the limits (as it would throw an exception when exceeding 30%) but it seems this margin is way too high and i might reduce it a bit. I've seen recommendations of about 12-15% of the whole QR matrix.

BTW, you've said "where we're at", so will you add a function to render the logo itself in the "LogoSpace"?

I still don't think adding the logo is focus of this library as it would only work in GD or Imagick output and break other modules. I made it easily extensible for that very reason. What i might add is positioning of the logo space, another implementation example and for the Imagick module an option to return the object instead of an image blob.

Again, thank you very much for the donation!

@codemasher
Copy link
Member

I've just added a simple example which creates QR Codes like the following:
image
I've also ported all of the above to the 3.x branch for support from PHP 7.2 onwards.

@renatofrota
Copy link

Wow!

I just need instructions on how to install the version compatible with PHP 7.2 using Composer. Apparently only releases are available there and the release 3.3.0 does not have these features you just added to 3.2.x branch. Is there a way to install the 3.2.x branch through Composer? Or could you publish a release of current 3.2.x branch?

Yeah, I am using 7.4 on my own projects, but I am working with a RAD application still pending on update their internal development ambient.

@codemasher
Copy link
Member

It's now released as 4.3.0 and 3.4.0 respectively. I didn't want to release around midnight - that would just have robbed my sleep.
Anyway, in cases of no current releases you could always access the branches directly via dev-main and v3.2.x-dev respectively (there's a list of valid branch names for composer over here).

Cheers!

@codemasher
Copy link
Member

deleted & re-released as the previous 3.4.0 tag pointed to the 4.x branch. sorry for any inconvenience, i am dumb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants