How does SVG compare to GD-Images in terms of creating high-quality diagrams in PHP?

SVG is generally preferred over GD-Images for creating high-quality diagrams in PHP because SVG allows for scalable vector graphics, which means the images can be scaled without losing quality. GD-Images, on the other hand, create raster graphics that can become pixelated when scaled. Additionally, SVG files are smaller in size and easier to manipulate programmatically.

<?php

// Create a simple SVG diagram with PHP
header('Content-Type: image/svg+xml');

echo '<?xml version="1.0" encoding="UTF-8"?>';
echo '<svg width="100" height="100" xmlns="http://www.w3.org/2000/svg">';
echo '<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />';
echo '</svg>';

?>