QrCodeController.php 899 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. class QrCodeController extends Controller
  5. {
  6. // 生成二维码
  7. public function index(Request $request)
  8. {
  9. $size = $request->get('size', 430);
  10. $margin = $request->get('margin', 2);
  11. $url = $request->get('url');
  12. list($c1, $c2, $c3) = explode(',', $request->get('color', '0,0,0'));
  13. list($b1, $b2, $b3) = explode(',', $request->get('bcolor', '255,255,255'));
  14. $logo = "https://www.fenpeiduixiang.com/favicon.ico";
  15. $result = \QrCode::format('png')
  16. ->size($size)
  17. ->margin($margin)
  18. ->merge($logo, 0.2, true)
  19. ->color($c1, $c2, $c3)
  20. ->backgroundColor($b1, $b2, $b3)
  21. ->errorCorrection('H')
  22. ->generate($url);
  23. return response($result, 200, ['Content-Type' => 'image/png']);
  24. }
  25. }