How to draw a square using SVG in PHP?

Viewed 121

I would like to create a square using SVG in PHP, given two parameters:

Side: (x, y) = e.g: 100; Corner: (rx, ry) = e.g: 20

Input:

enter image description here

Output:

enter image description here

My code works, but I'm looking for a simplified version ...

Code:

  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";

}

Full code: Input: form.php> https://pastebin.com/H3PpJgb6 Output: result.php> https://pastebin.com/PGpGJBRN

Any ideas?

1 Answers

Not sure if it is "simpler" than what you have, but check out the rectangle function of imagickdraw here and here.

Related