Quickstart.md.txt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # Quickstart
  2. ## Import the library
  3. Import the main class(es) and include the autoloader (if necessary):
  4. ```php
  5. use chillerlan\QRCode\{QRCode, QROptions};
  6. require_once __DIR__.'/../vendor/autoload.php';
  7. ```
  8. ## Create your first QR Code
  9. We want to encode this URI for a mobile authenticator into a QRcode image:
  10. ```php
  11. $data = 'otpauth://totp/test?secret=B3JX4VCVJDVNXNZ5&issuer=chillerlan.net';
  12. $qrcode = (new QRCode)->render($data);
  13. // default output is a base64 encoded data URI
  14. printf('<img src="%s" alt="QR Code" />', $qrcode);
  15. ```
  16. ### Configuration
  17. Configuration using `QROptions`:
  18. ```php
  19. $options = new QROptions;
  20. $options->version = 7;
  21. $options->outputBase64 = false; // output raw image instead of base64 data URI
  22. header('Content-type: image/svg+xml'); // the image type is SVG by default
  23. echo (new QRCode($options))->render($data);
  24. ```
  25. See [Advanced usage](../Usage/Advanced-usage.md) for a more in-depth usage guide
  26. and [configuration settings](../Usage/Configuration-settings.md) for a list of available options.
  27. Also, have a look [in the examples folder](https://github.com/chillerlan/php-qrcode/tree/main/examples) for some more usage examples.
  28. ## Notes
  29. The QR encoder, especially the subroutines for mask pattern testing, can cause high CPU load on increased matrix size.
  30. You can avoid a part of this load by choosing a fast output module, like SVG.
  31. Oh hey and don't forget to sanitize any user input!