簡體   English   中英

如何在 PHP 中使用 SVG 繪制正方形?

[英]How to draw a square using SVG in PHP?

我想在 PHP 中使用 SVG 創建一個正方形,給定兩個參數:

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

輸入:

在此處輸入圖像描述

Output:

在此處輸入圖像描述

我的代碼有效,但我正在尋找一個簡化版本......

代碼:

  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 Output: result.php> Z5E056C500A1C4B6A7110B50D807GBRN5Z://pastebin.com

有任何想法嗎?

不確定它是否比您擁有的“更簡單”,但請查看 imagickdraw herehere的矩形 function 。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM