fpdf.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * FPDF output example
  4. *
  5. * @created 03.06.2020
  6. * @author Maximilian Kresse
  7. * @license MIT
  8. */
  9. use chillerlan\QRCode\{QRCode, QROptions};
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\Output\QROutputInterface;
  12. require_once __DIR__ . '/../vendor/autoload.php';
  13. $options = new QROptions;
  14. $options->version = 7;
  15. $options->outputType = QROutputInterface::FPDF;
  16. $options->scale = 5;
  17. $options->fpdfMeasureUnit = 'mm';
  18. $options->bgColor = [222, 222, 222];
  19. $options->drawLightModules = false;
  20. $options->outputBase64 = false;
  21. $options->moduleValues = [
  22. // finder
  23. QRMatrix::M_FINDER_DARK => [0, 63, 255], // dark (true)
  24. QRMatrix::M_FINDER_DOT => [0, 63, 255], // finder dot, dark (true)
  25. QRMatrix::M_FINDER => [255, 255, 255], // light (false)
  26. // alignment
  27. QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
  28. QRMatrix::M_ALIGNMENT => [255, 255, 255],
  29. // timing
  30. QRMatrix::M_TIMING_DARK => [255, 0, 0],
  31. QRMatrix::M_TIMING => [255, 255, 255],
  32. // format
  33. QRMatrix::M_FORMAT_DARK => [67, 191, 84],
  34. QRMatrix::M_FORMAT => [255, 255, 255],
  35. // version
  36. QRMatrix::M_VERSION_DARK => [62, 174, 190],
  37. QRMatrix::M_VERSION => [255, 255, 255],
  38. // data
  39. QRMatrix::M_DATA_DARK => [0, 0, 0],
  40. QRMatrix::M_DATA => [255, 255, 255],
  41. // darkmodule
  42. QRMatrix::M_DARKMODULE => [0, 0, 0],
  43. // separator
  44. QRMatrix::M_SEPARATOR => [255, 255, 255],
  45. // quietzone
  46. QRMatrix::M_QUIETZONE => [255, 255, 255],
  47. ];
  48. $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  49. if(php_sapi_name() !== 'cli'){
  50. header('Content-type: application/pdf');
  51. }
  52. echo $out;
  53. exit;