2
0

ProgressImgController.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Http\Response;
  5. use Illuminate\Support\Facades\Cache;
  6. class ProgressImgController extends Controller
  7. {
  8. /**
  9. * Display a listing of the resource.
  10. *
  11. * @return Response
  12. */
  13. public function index()
  14. {
  15. //
  16. }
  17. /**
  18. * Store a newly created resource in storage.
  19. *
  20. * @return Response
  21. */
  22. public function store(Request $request)
  23. {
  24. //
  25. }
  26. /**
  27. * Display the specified resource.
  28. *
  29. * @param string $id
  30. * @return Response
  31. */
  32. public function show($id)
  33. {
  34. //
  35. return response()->stream(function () use ($id) {
  36. $key = str_replace('-', '/', $id);
  37. $svg = Cache::remember('svg/'.$key, config('mint.cache.expire'), function () use ($key) {
  38. $viewHeight = 60;
  39. $svg = "<svg xmlns='http://www.w3.org/2000/svg' fill='currentColor' viewBox='0 0 300 60'>";
  40. $data = Cache::get($key);
  41. if (is_array($data)) {
  42. $point = [];
  43. foreach ($data as $key => $value) {
  44. $point[] = ($key * 10).','.$viewHeight - ($value / 20) - 3;
  45. }
  46. $svg .= '<polyline points="'.implode(' ', $point).'"';
  47. $svg .= ' style="fill:none;stroke:green;stroke-width:3" /></svg>';
  48. } else {
  49. $svg .= '<polyline points="0,0 1,0" /></svg>';
  50. }
  51. return $svg;
  52. });
  53. echo $svg;
  54. }, 200, ['Content-Type' => 'image/svg+xml']);
  55. /*
  56. ————————————————
  57. 原文作者:Summer
  58. 转自链接:https://learnku.com/laravel/wikis/25600
  59. 版权声明:著作权归作者所有。商业转载请联系作者获得授权,非商业转载请保留以上作者信息和原文链接。
  60. */
  61. }
  62. /**
  63. * Update the specified resource in storage.
  64. *
  65. * @param int $id
  66. * @return Response
  67. */
  68. public function update(Request $request, $id)
  69. {
  70. //
  71. }
  72. /**
  73. * Remove the specified resource from storage.
  74. *
  75. * @param int $id
  76. * @return Response
  77. */
  78. public function destroy($id)
  79. {
  80. //
  81. }
  82. }