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

Can't put logo on the qrcode when using merge or mergeString png image #280

Open
9khaledSayed opened this issue Apr 24, 2023 · 2 comments
Open

Comments

@9khaledSayed
Copy link

Hello t still not working it generate an random charcters like that:-
image
$qrCode = QrCode::gradient(28, 181, 224, 0, 8, 81, 'horizontal') ->format('png')->merge(asset('beta-logos/small-logo.png'), .3, true) ->style('dot', 0.9) ->size(95) ->eyeColor(0, 28, 181, 224, 0, 8, 81) ->eyeColor(1, 28, 181, 224, 0, 8, 81) ->eyeColor(2, 28, 181, 224, 0, 8, 81) ->generate(route('generate_pdf', $invoice->id));
and the path of my photo is this https://beta-plus.jevara.fun/public/beta-logos/small-logo.png

@9khaledSayed
Copy link
Author

9khaledSayed commented Apr 24, 2023

same issue if i use public_path instead of asset() method

code-snapshot

@simonhamp
Copy link

This happens because you're using format('png') - by default this library outputs an SVG, which is just a string of XML that the browser can render natively.

But a PNG is a binary format and so you'll need an <img /> tag to render it.

But the browser can't render the binary data directly as the encoding could break your HTML, so the safest way to load the binary directly into the page is a base64-encoded string:

- $qrCode = QrCode::gradient(28, 181, 224, 0, 8, 81, 'horizontal')
+ $qrCode = base64_encode(QrCode::gradient(28, 181, 224, 0, 8, 81, 'horizontal')
    ->format('png')
    ->merge(asset('beta-logos/small-logo.png'), .3, true)
    ->style('dot', 0.9)
    ->size(95)
    ->eyeColor(0, 28, 181, 224, 0, 8, 81)
    ->eyeColor(1, 28, 181, 224, 0, 8, 81)
    ->eyeColor(2, 28, 181, 224, 0, 8, 81)
-    ->generate(route('generate_pdf', $invoice->id));
+    ->generate(route('generate_pdf', $invoice->id)));

Then you can render the image tag using an inline data flag like this

<img src="data:image/png;base64,{{ $qrCode }}" />

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

2 participants