image.php 2.3 KB

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