我正在使用 Composer endroid/qr-code php 包生成 QR 码。
这太酷了,这是我用于生成 SVG 的 PHP 设置。
// 创建二维码
$qrCode = QrCode::create($url)
->setEncoding(new Encoding('UTF-8'))
->setErrorCorrectionLevel(new ErrorCorrectionLevelLow())
->setSize(210)
->setMargin(0)
->setRoundBlockSizeMode(new RoundBlockSizeModeMargin())
->setForegroundColor(new Color(0,0,0))
->setBackgroundColor(new Color(255,255,255));
它以 SVG 格式输出这个很棒的 QR 代码...(为了演示而稍微缩小)
运行下面的代码片段以查看在 HTML 中运行的 SVG 代码...
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="210px" height="210px" viewBox="0 0 210 210">
<defs>
<rect id="block" width="30" height="30" fill="#000000" />
</defs>
<rect x="0" y="0" width="210" height="210" fill="#ffffff" />
<use x="0" y="0" href="#block"></use>
<use x="30" y="0" href="#block"></use>
<use x="60" y="0" href="#block"></use>
<use x="90" y="0" href="#block"></use>
<use x="120" y="0" href="#block"></use>
<use x="150" y="0" href="#block"></use>
<use x="180" y="0" href="#block"></use>
<use x="0" y="30" href="#block"></use>
<use x="180" y="30" href="#block"></use>
<use x="0" y="60" href="#block"></use>
<use x="60" y="60" href="#block"></use>
<use x="90" y="60" href="#block"></use>
<use x="120" y="60" href="#block"></use>
<use x="180" y="60" href="#block"></use>
<use x="0" y="90" href="#block"></use>
<use x="60" y="90" href="#block"></use>
<use x="90" y="90" href="#block"></use>
<use x="120" y="90" href="#block"></use>
<use x="180" y="90" href="#block"></use>
<use x="0" y="120" href="#block"></use>
<use x="60" y="120" href="#block"></use>
<use x="90" y="120" href="#block"></use>
<use x="120" y="120" href="#block"></use>
<use x="180" y="120" href="#block"></use>
<use x="0" y="150" href="#block"></use>
<use x="180" y="150" href="#block"></use>
<use x="0" y="180" href="#block"></use>
<use x="30" y="180" href="#block"></use>
<use x="60" y="180" href="#block"></use>
<use x="90" y="180" href="#block"></use>
<use x="120" y="180" href="#block"></use>
<use x="150" y="180" href="#block"></use>
<use x="180" y="180" href="#block"></use>
</svg>
但我没有尝试过在 Illustrator 中打开我的二维码。
这段代码在我的预览中工作IDE
,预览Mac
,它在 html 页面上使用时可以正常打开Chrome
并显示良好,但不能在Illustrator
.
当我在 Illustrator 中打开它时,它只显示一个白色框。
为什么此 SVG 代码无法在 Adobe Illustrator 中运行?
如何修复 SVG 代码以使其在 Illustrator 中工作?
我使用的是最新版本的 Adobe Illustrator 28.0。
来自成员 @joshmoto的问题Cannot open generated QR code SVG in Adobe Illustrator的免费翻译。
看起来 Adobe Illustrator尚不支持属性
href
并且需要xlink:href
.进行此更改时,您还需要
xmlns:xlink="http://www.w3.org/1999/xlink"
向根元素添加一个属性。实际上,我认为您用来生成输出的代码包含一个命令
Force_xlink_href
,因此您应该使用它,它会为您完成所有操作。会员 @Robert Longson的答案的免费翻译 。