[英]How to save generated qr Code in laravel?
I have generated QR code using "simplesoftwareio/simple-qrcode": https://github.com/SimpleSoftwareIO/simple-qrcode我使用“simplesoftwareio/simple-qrcode”生成了二维码: https://github.com/SimpleSoftwareIO/simple-qrcode
Now I want to save the generated image in my local drive.现在我想将生成的图像保存在我的本地驱动器中。 How can I do it?我该怎么做?
public function qr($id)
{
$data = Ticket::get()->find($id);
$image = \QrCode::format('png')
->merge('img/t.jpg', 0.1, true)
->size(200)->errorCorrection('H')
->generate('A simple example of QR code!');
return response($image)->header('Content-type','image/png');
return view('qrCode', compact('qrData', $qrData));
}
You can try你可以试试
$image = \QrCode::format('png')
->merge('img/t.jpg', 0.1, true)
->size(200)->errorCorrection('H')
->generate('A simple example of QR code!');
$output_file = '/img/qr-code/img-' . time() . '.png';
Storage::disk('local')->put($output_file, $image); //storage/app/public/img/qr-code/img-1557309130.png
你可以为公众尝试这个
Storage::disk('public')->put($output_file, $image); //storage/app/public/img/qr-code/img-1557309130.png
$data = new ModelName();
$path = '/img/qr-code/img/';
if(!\File::exists(public_path($path))) {
\File::makeDirectory(public_path($path));
}
$file_path = $path . time() . '.png';
$image = \QrCode::format('png')
->merge('img/t.jpg', 0.1, true)
->size(200)->errorCorrection('H')
->generate('A simple example of QR code!', $file_path)
$data->field_name = $file_path;
$data->save();
I hope this will help you, it works fine for me
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.