image.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @created 24.12.2017
  4. * @author Smiley <smiley@chillerlan.net>
  5. * @copyright 2017 Smiley
  6. * @license MIT
  7. */
  8. namespace chillerlan\QRCodeExamples;
  9. use chillerlan\QRCode\{QRCode, QROptions};
  10. use chillerlan\QRCode\Data\QRMatrix;
  11. use chillerlan\QRCode\Common\EccLevel;
  12. use Throwable;
  13. require_once __DIR__.'/../vendor/autoload.php';
  14. $data = 'https://www.youtube.com/watch?v=DLzxrzFCyOs&t=43s';
  15. $options = new QROptions([
  16. 'version' => 7,
  17. 'outputType' => QRCode::OUTPUT_IMAGE_PNG,
  18. 'eccLevel' => EccLevel::L,
  19. 'scale' => 10,
  20. 'imageBase64' => false,
  21. 'imageTransparent' => false,
  22. 'drawCircularModules' => true,
  23. 'circleRadius' => 0.4,
  24. 'keepAsSquare' => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
  25. 'moduleValues' => [
  26. // finder
  27. QRMatrix::M_FINDER | QRMatrix::IS_DARK => [0, 63, 255], // dark (true)
  28. QRMatrix::M_FINDER => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
  29. QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => [0, 63, 255], // finder dot, dark (true)
  30. // alignment
  31. QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK => [255, 0, 255],
  32. QRMatrix::M_ALIGNMENT => [233, 233, 233],
  33. // timing
  34. QRMatrix::M_TIMING | QRMatrix::IS_DARK => [255, 0, 0],
  35. QRMatrix::M_TIMING => [233, 233, 233],
  36. // format
  37. QRMatrix::M_FORMAT | QRMatrix::IS_DARK => [67, 159, 84],
  38. QRMatrix::M_FORMAT => [233, 233, 233],
  39. // version
  40. QRMatrix::M_VERSION | QRMatrix::IS_DARK => [62, 174, 190],
  41. QRMatrix::M_VERSION => [233, 233, 233],
  42. // data
  43. QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
  44. QRMatrix::M_DATA => [233, 233, 233],
  45. // darkmodule
  46. QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => [0, 0, 0],
  47. // separator
  48. QRMatrix::M_SEPARATOR => [233, 233, 233],
  49. // quietzone
  50. QRMatrix::M_QUIETZONE => [233, 233, 233],
  51. // logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
  52. QRMatrix::M_LOGO => [233, 233, 233],
  53. ],
  54. ]);
  55. try{
  56. $im = (new QRCode($options))->render($data);
  57. }
  58. catch(Throwable $e){
  59. exit($e->getMessage());
  60. }
  61. header('Content-type: image/png');
  62. echo $im;