eps.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. /**
  3. * @created 10.05.2022
  4. * @author Smiley <smiley@chillerlan.net>
  5. * @copyright 2022 Smiley
  6. * @license MIT
  7. */
  8. use chillerlan\QRCode\{QRCode, QROptions};
  9. use chillerlan\QRCode\Common\EccLevel;
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\Output\QROutputInterface;
  12. require_once __DIR__.'/../vendor/autoload.php';
  13. $options = new QROptions([
  14. 'version' => 7,
  15. 'outputType' => QROutputInterface::EPS,
  16. 'eccLevel' => EccLevel::L,
  17. 'scale' => 5,
  18. 'addQuietzone' => true,
  19. 'drawLightModules' => false,
  20. 'cachefile' => __DIR__.'/test.eps', // save to file
  21. '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 => [233, 233, 233], // light (false)
  26. // alignment
  27. QRMatrix::M_ALIGNMENT_DARK => [255, 0, 255],
  28. QRMatrix::M_ALIGNMENT => [233, 233, 233],
  29. // timing
  30. QRMatrix::M_TIMING_DARK => [255, 0, 0],
  31. QRMatrix::M_TIMING => [233, 233, 233],
  32. // format
  33. QRMatrix::M_FORMAT_DARK => [67, 159, 84],
  34. QRMatrix::M_FORMAT => [233, 233, 233],
  35. // version
  36. QRMatrix::M_VERSION_DARK => [62, 174, 190],
  37. QRMatrix::M_VERSION => [233, 233, 233],
  38. // data
  39. QRMatrix::M_DATA_DARK => [0, 0, 0],
  40. QRMatrix::M_DATA => [233, 233, 233],
  41. // darkmodule
  42. QRMatrix::M_DARKMODULE => [0, 0, 0],
  43. // separator
  44. QRMatrix::M_SEPARATOR => [233, 233, 233],
  45. // quietzone
  46. QRMatrix::M_QUIETZONE => [233, 233, 233],
  47. // logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
  48. QRMatrix::M_LOGO => [233, 233, 233],
  49. ],
  50. ]);
  51. if(php_sapi_name() !== 'cli'){
  52. // if viewed in the browser, we should push it as file download as EPS isn't usually supported
  53. header('Content-type: application/postscript');
  54. header('Content-Disposition: filename="qrcode.eps"');
  55. }
  56. echo (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  57. exit;