intervention-image.php 2.2 KB

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