问题描述
我一直在尝试将 QRcode SVG 文件转换为 PNG 格式。
以下确实返回一个空的黑色图像,但没有内容。我想将所有内容从 SVG 格式转换为 PNG 格式:
$file = SVG::fromFile(storage_path('app/public/qr_background.svg'));
$background = $file->getDocument();
$qrString = QrCode::size('2500')
->style('round')
->backgroundColor(0,1)
->generate(
env('FARMCODE_BASE_URL')
? env('FARMCODE_BASE_URL') . $product->id
: route('product-landingpage',['product' => $product])
);
$qr = SVG::fromString($qrString)->getDocument();
$qr->getChild(1)->setAttribute('transform',"translate(450,450) scale(44)");
$background->addChild($qr);
$name = 'abc.png';
// Make image with Laravel Invervention package
$image = Image::make($file->toRasterImage(2000,2000))->encode('png');
$headers = [
'Content-Type' => 'image/png','Content-disposition' => 'attachment; filename='. $name,];
return response()->stream(function() use ($image) {
echo $image;
},200,$headers);
我正在使用 meyfa/PHP-svg
simplesoftwareio/simple-qrcode
和 intervention/image
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)