2
0

ProgressImgController.php 2.5 KB

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