5

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!

2
  • 1
    <img src="/image_gen.php" />
    – Kryten
    Jan 10, 2017 at 19:34
  • This displays a failed resource image. The php file needs a bit of meta data to tell the image tag to process it as an image, not a php file.
    – Ryan
    Jan 10, 2017 at 19:35

1 Answer 1

7

Using the following PHP code, I set the content type of the file to svg+xml:

<?php
    header('Content-Type: image/svg+xml');
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.