So, I'm attempting to create some tag images for my users, showing the total points that they have earned. I am attempting to write the SVG in a php file which will add in dynamic content, such as the user's points. I'd like to use a HTML <img>
tag to fetch the SVG from a file image_gen.php
.
How would I display the SVG through the <img>
tag?
Thanks!
Echo the SVG with PHP php”. This adjustment instructs the server to process the file as a PHP file. Second, add the Content-type: image/svg+xml HTTP header to the generated document. This second change tells the browser to display the document as an SVG.
SVG stands for Scalable Vector Graphics. SVG defines vector-based graphics in XML format.
php $svg_file = file_get_contents('http://example.com/logo.svg'); $find_string = '<svg'; $position = strpos($svg_file, $find_string); $svg_file_new = substr($svg_file, $position); echo "<div style='width:100%; height:100%;' >" .
What is an SVG file? Scalable Vector Graphics (SVG) is a web-friendly vector file format. As opposed to pixel-based raster files like JPEGs, vector files store images via mathematical formulas based on points and lines on a grid.
Using the following PHP code, I set the content type of the file to svg+xml
:
<?php
header('Content-Type: image/svg+xml');
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With