使用PHP生成SVG文件

时间:2017-01-10 19:32:09

标签: php html svg

因此,我尝试为我的用户创建一些标记图像,显示他们获得的总分。我试图在一个php文件中编写SVG,它将添加动态内容,例如用户的观点。我想使用HTML <image>代码从文件image_gen.php获取SVG。

如何通过<image>标签显示SVG?

谢谢!

1 个答案:

答案 0 :(得分:1)

使用以下PHP代码,我将文件的内容类型设置为<?php header('Content-Type: image/svg+xml'); ?>

<style>
    #donationad {
        position: fixed;
        bottom: 0;
        left: 40px;
        width: 250px;
        height: 150px;
        z-index: 999;
        display: none;
    }

    #donationad.hide {
        display: none;
    }

    .closebutton {
        position: relative;
        top: 20px;
        left: 230px;
        cursor: pointer;
    }

    .closebutton img {
        width: 30px;
        height: auto;
        opacity: 1.0;
    }
</style>
<script type="text/javascript">
    $(document).ready(function() {
        $('.closebutton').click(function() {
            $("#donationad").toggleClass("hide");
        });
    });
</script>
<div id="donationad">
    <div class="closebutton"> <img src="http://www.dbknews.com/pb/resources/assets/img/modal_close_button.png"> </div>
    <a href="http://dbknews.com/donate"> <img src="https://s3.amazonaws.com/wapopartners.com/dbknews-wp/wp-content/uploads/2016/12/24020402/DBK-Donate250x150.jpg"> </a>
</div>
<script type="text/javascript">
    var cookie = document.cookie;
    if (cookie.indexOf('visited=', 0) == -1) {
        var expiration = new Date();
        expiration.setDate(expiration.getDate() + 1);
        document.cookie = 'visited=1;expires=' + expiration + ';path=/';
        var element = document.getElementById('donationad');
        element.style.display = 'block';
    }
</script>