【问题标题】:How to draw a square using SVG in PHP?如何在 PHP 中使用 SVG 绘制正方形?
【发布时间】:2021-06-18 18:03:58
【问题描述】:

我想在 PHP 中使用 SVG 创建一个正方形,给定两个参数:

边:(x, y) = 例如:100; 角点:(rx, ry) = 例如:20

输入:

输出:

我的代码有效,但我正在寻找一个简化版本...

代码:

  if ($sideOK && $cornerOK){
print " <svg version=\"1.1\" xmlns=\"http:/www.w3.org/2000/svg\"\n"
. " width=\"" .($side+10) ."px\" height=\"" . ($side + 10) . "px\">\n";
print " <rect fill=\"white\" stroke=\"black\" stroke-width=\"10\" "
. "x=\"5\" y=\"5\" width=\"$side\" height=\"$side\" rx=\"$corner\" ry=\"$corner\" />\n";
print " </svg>\n";
print "\n";

}

完整代码: 输入:form.php>https://pastebin.com/H3PpJgb6 输出:result.php>https://pastebin.com/PGpGJBRN

有什么想法吗?

【问题讨论】:

  • &lt;svg width="100" height="100"&gt;&lt;rect width="100" height="100" style="fill:rgb(0,0,255);" /&gt;&lt;/svg&gt; 这是简单的 html/svg 方码。可能会有帮助。
  • 谢谢,但这是我在 html 中使用的内联代码,但我还没有让它在 php 中工作

标签: javascript php html svg


【解决方案1】:

不确定它是否比您拥有的“更简单”,但请查看 imagickdraw herehere 的矩形函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-20
    • 2016-01-23
    • 2017-02-12
    • 2023-03-26
    相关资源
    最近更新 更多