如何实时生成图片并且下载?
现在网站经常会用到二维码, 用了一下simple qrcode
感觉还是挺方便的.
例如
- 直接生成svg
{{ QrCode::generate('Make me into a QrCode!'); }}
- 生成png
<img src="data:image/png;base64, {{ base64_encode(QrCode::format('png')->size(100)->generate('Make me into an QrCode!')); }} ">
但是如果用户需要保存图片的话,必须点击右键保存. 如何能够实时生成二维码图片并且直接下载呢?
我尝试了一下,感觉不太对
Route::get('/qrcode',function(){
return Response::stream(function(){
return $qrc = QrCode::format('png')->size(200)->generate('http://wwww.baidu.com');
},200,["Content-type"=>"image/png","Content-Disposition"=>"attachment; filename=hello.png"]);
});
点击链接确实能直接下载,但是生成的文件无法打开.不知道是哪里错了. 希望大家一起讨论一下.
推荐文章: