image.php 2.5 KB

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