image.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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' => [QRMatrix::M_FINDER|QRMatrix::IS_DARK, QRMatrix::M_FINDER_DOT, QRMatrix::M_ALIGNMENT|QRMatrix::IS_DARK],
  24. 'moduleValues' => [
  25. // finder
  26. QRMatrix::M_FINDER | QRMatrix::IS_DARK => [0, 63, 255], // dark (true)
  27. QRMatrix::M_FINDER => [233, 233, 233], // light (false), white is the transparency color and is enabled by default
  28. QRMatrix::M_FINDER_DOT | QRMatrix::IS_DARK => [0, 63, 255], // finder dot, dark (true)
  29. // alignment
  30. QRMatrix::M_ALIGNMENT | QRMatrix::IS_DARK => [255, 0, 255],
  31. QRMatrix::M_ALIGNMENT => [233, 233, 233],
  32. // timing
  33. QRMatrix::M_TIMING | QRMatrix::IS_DARK => [255, 0, 0],
  34. QRMatrix::M_TIMING => [233, 233, 233],
  35. // format
  36. QRMatrix::M_FORMAT | QRMatrix::IS_DARK => [67, 159, 84],
  37. QRMatrix::M_FORMAT => [233, 233, 233],
  38. // version
  39. QRMatrix::M_VERSION | QRMatrix::IS_DARK => [62, 174, 190],
  40. QRMatrix::M_VERSION => [233, 233, 233],
  41. // data
  42. QRMatrix::M_DATA | QRMatrix::IS_DARK => [0, 0, 0],
  43. QRMatrix::M_DATA => [233, 233, 233],
  44. // darkmodule
  45. QRMatrix::M_DARKMODULE | QRMatrix::IS_DARK => [0, 0, 0],
  46. // separator
  47. QRMatrix::M_SEPARATOR => [233, 233, 233],
  48. // quietzone
  49. QRMatrix::M_QUIETZONE => [233, 233, 233],
  50. // logo (requires a call to QRMatrix::setLogoSpace()), see QRImageWithLogo
  51. QRMatrix::M_LOGO => [233, 233, 233],
  52. ],
  53. ]);
  54. try{
  55. $im = (new QRCode($options))->render('https://www.youtube.com/watch?v=dQw4w9WgXcQ');
  56. }
  57. catch(Throwable $e){
  58. exit($e->getMessage());
  59. }
  60. header('Content-type: image/png');
  61. echo $im;
  62. exit;