eps.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. /**
  3. * EPS output example
  4. *
  5. * @created 10.05.2022
  6. * @author Smiley <smiley@chillerlan.net>
  7. * @copyright 2022 Smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\{QRCode, QROptions};
  11. use chillerlan\QRCode\Data\QRMatrix;
  12. use chillerlan\QRCode\Output\QROutputInterface;
  13. require_once __DIR__.'/../vendor/autoload.php';
  14. $options = new QROptions;
  15. $options->version = 7;
  16. $options->outputType = QROutputInterface::EPS;
  17. $options->scale = 5;
  18. $options->drawLightModules = false;
  19. // colors can be specified either as [R, G, B] or [C, M, Y, K] (0-255)
  20. $options->bgColor = [222, 222, 222];
  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 => [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 space (requires a call to QRMatrix::setLogoSpace()), see imageWithLogo example
  48. QRMatrix::M_LOGO => [233, 233, 233],
  49. ];
  50. $out = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ', __DIR__.'/qrcode.eps');
  51. if(PHP_SAPI !== '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 $out;
  57. exit;