image.php 2.2 KB

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