2

I'm currently using this Plugin to generate QR-Codes on my site. These QR-Codes are used for products, so it refers to a special product when downloading.

This is the code I use to generate it and make it able to be downloaded:

   <a href="data:image/png;base64, <?php echo base64_encode(QrCode::format('png')->size(500)->encoding('UTF-8')->errorCorrection('H')->generate('‌https://localhost/product/'.$product->id));?> "
                                           download=<?=$product->name."_QRCode";?>>
                                            <img src="data:image/png;base64, <?php echo base64_encode(QrCode::format('png')->margin(1)->size(50)->encoding('UTF-8')->errorCorrection('H')->generate('‌https://localhost/product/'.$product->id));?>">
                                        </a>

Now comes the clue: Like this, somebody could download 10 QR-Codes but would have no idea, where this QR-Code belongs to. Therefore, I want the downloaded QR-Code to be merged with a string... But as the docs say, that The merge method only supports PNG at this time I guess it's not possible to do this directly. But I'm wondering if there is a way in PHP (and also with Laravel, which I'm using, if this changes something) to generate an image (a png) out of a string I enter, so something like (pseudoCode follows):

$mergeText = $product->name;
$image = stringToPng($mergeText);
//maybe instead convert to base64 image, like the qr-code? don't know
QrCode::format('png')->size(500)->encoding('UTF-8')->errorCorrection('H')->merge($image)->generate('‌https://localhost/product/'.$product->id));?>

Does anybody know if this is possible?

nameless
  • 1,483
  • 5
  • 32
  • 78
  • Can you explain a bit more what do you want as a result? An example image maybe? I'm not sure what you want. Do you want an image in your QR? or another thing? – Gerard Reches Dec 01 '16 at 10:10
  • @Gerard Reches its possible to merge images into a qr-code, often that is a company image or something.. What I want is to convert a string/text, something like "Samsung Galaxy S7" to a png, having a white or transparent background with the text, so I can then load this png into the qr code as image, you know what I mean? – nameless Dec 01 '16 at 12:51
  • You want the string as itself in front/behind the QR code? – Gerard Reches Dec 01 '16 at 13:05
  • What I mean is QR-Codes like this (https://raw.githubusercontent.com/SimpleSoftwareIO/simple-qrcode/master/docs/imgs/merged-qrcode.png?raw=true), instead the image I want the text as image like I created here as an example : http://fs5.directupload.net/images/161201/orkxtmyk.png – nameless Dec 01 '16 at 13:21
  • Ok, that's what I want to know. – Gerard Reches Dec 01 '16 at 13:49

1 Answers1

1

It's possible, but not in the way you are trying to do it.

First, you have to convert your text to an image. How to do this should be your main question, you can try with this answer: convert text to image in php.

When you already have the PNG image, then you will be able to use the merge method.

Community
  • 1
  • 1
Gerard Reches
  • 3,048
  • 3
  • 28
  • 39
  • After some research I found that thread as well, but somehow I had problems getting it running, seems like because of the font, I tried everything to get it working with `Arial.ttf`, I used it just like I wrote, as `Arial.ttf`, moved it to the same directory, then using `./Arial.ttf`, or move it to the public directory and then using `/Arial.ttf` but nothing was working.. – nameless Dec 01 '16 at 14:42