-1

I can't save the qrcode and datamatrix images produced by the milon barcode package in memory, getting this error: The non-static method Milon\Barcode\DNS2D::getBarcodePNG() cannot be called statically

On images produced in DNS1D I can save it correctly using the base64_decode function, while the problem occurs with saving DNS2D... This is my code: insert image description here

$pathQr_code = 'documents/qrcode/'. 'azienda-' . $business->id . '_posta-' . $post->id . '.png';
$qr_code = Storage::disk('public')->put($pathQr_code , base64_decode(DNS2D::getBarcodePNG("$post->qr_code", 'QRCODE')));

I've tried different ways but I can't figure out what's wrong.... Can anyone help me?

  • Your error is saying that `getBarcodePNG` is not a Static Method, so you can't call it statically via `DNS2D::getBarcodePNG`. You can try `(new DNS2D())->getBarcodePNG(...)` instead maybe? – Tim Lewis Jul 07 '23 at 15:09
  • Thank you very much I tried as suggested and it seems to work correctly! – VALERIO MATRANGA Jul 07 '23 at 15:23
  • Excellent! Please make sure to read up on the `static` keyword in PHP and how to access static and non-static methods class methods. Cheers – Tim Lewis Jul 07 '23 at 15:29
  • to save the images you must always encode them in base64 Ex: Es: base64_decode((new DNS2D())->getBarcodePNG("$post->qr_code", DATAMATRIX')); – VALERIO MATRANGA Jul 07 '23 at 15:39
  • Sidenote, this is the comments section; if you've got a solution, post it in the answers section below – Tim Lewis Jul 07 '23 at 15:46

1 Answers1

1

I fixed it as suggested by Tim Lewis by declaring a new instance of DNS2D and wrapping everything with base64_decode.

 base64_decode((new DNS2D())->getBarcodePNG("$post->qr_code", DATAMATRIX'));