intervention-image.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * intervention/image output example
  4. *
  5. * @created 04.05.2024
  6. * @author smiley <smiley@chillerlan.net>
  7. * @copyright 2024 smiley
  8. * @license MIT
  9. */
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\Output\QRInterventionImage;
  12. use chillerlan\QRCode\QRCode;
  13. use chillerlan\QRCode\QROptions;
  14. use Intervention\Image\Drivers\Gd\Driver as GdDriver;
  15. require_once __DIR__.'/../vendor/autoload.php';
  16. $options = new QROptions;
  17. $options->version = 7;
  18. $options->outputInterface = QRInterventionImage::class;
  19. $options->scale = 20;
  20. $options->outputBase64 = false;
  21. $options->bgColor = '#cccccc';
  22. $options->imageTransparent = false;
  23. $options->transparencyColor = '#cccccc';
  24. $options->drawLightModules = true;
  25. $options->drawCircularModules = true;
  26. $options->circleRadius = 0.4;
  27. $options->keepAsSquare = [
  28. QRMatrix::M_FINDER_DARK,
  29. QRMatrix::M_FINDER_DOT,
  30. QRMatrix::M_ALIGNMENT_DARK,
  31. ];
  32. $options->moduleValues = [
  33. // finder
  34. QRMatrix::M_FINDER_DARK => '#A71111', // dark (true)
  35. QRMatrix::M_FINDER_DOT => '#A71111', // finder dot, dark (true)
  36. QRMatrix::M_FINDER => '#FFBFBF', // light (false)
  37. // alignment
  38. QRMatrix::M_ALIGNMENT_DARK => '#A70364',
  39. QRMatrix::M_ALIGNMENT => '#FFC9C9',
  40. // timing
  41. QRMatrix::M_TIMING_DARK => '#98005D',
  42. QRMatrix::M_TIMING => '#FFB8E9',
  43. // format
  44. QRMatrix::M_FORMAT_DARK => '#003804',
  45. QRMatrix::M_FORMAT => '#CCFB12',
  46. // version
  47. QRMatrix::M_VERSION_DARK => '#650098',
  48. QRMatrix::M_VERSION => '#E0B8FF',
  49. // data
  50. QRMatrix::M_DATA_DARK => '#4A6000',
  51. QRMatrix::M_DATA => '#ECF9BE',
  52. // darkmodule
  53. QRMatrix::M_DARKMODULE => '#080063',
  54. // separator
  55. QRMatrix::M_SEPARATOR => '#DDDDDD',
  56. // quietzone
  57. QRMatrix::M_QUIETZONE => '#DDDDDD',
  58. ];
  59. $qrcode = new QRCode($options);
  60. $qrcode->addByteSegment('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  61. $qrOutputInterface = new QRInterventionImage($options, $qrcode->getQRMatrix());
  62. // set a different driver
  63. $qrOutputInterface->setDriver(new GdDriver);
  64. $out = $qrOutputInterface->dump();
  65. header('Content-type: image/png');
  66. echo $out;
  67. exit;