简体   繁体   中英

PHP using imagecreatefromstring to convert an SVG string to image

The following javascript code will convert an SVG string into a image blob that can then be used to display in a browser:

 var data = '<svg xmlns="http://www.w3.org/2000/svg" width="390" height="65">' +
        '<rect x="0" y="0" width="100%" height="100%" fill="#7890A7" stroke-width="20" stroke="#ffffff" ></rect>' +
        '<foreignObject x="15" y="10" width="100%" height="100%">' +
        '<div xmlns="http://www.w3.org/1999/xhtml" style="font-size:40px">' +
        ' <em>I</em> am' +
        '<span style="color:white; text-shadow:0 0 20px #000000;">' +
        ' HTML in SVG!</span>' +
        '</div>' +
        '</foreignObject>' +
        '</svg>';

    var DOMURL = window.URL || window.webkitURL || window;

    var img = new Image();
    var svg = new Blob([data], {type: 'image/svg+xml;charset=utf-8'});
    var url = DOMURL.createObjectURL(svg);

The trouble is that i want to be able to do this same thing but in PHP. I thought about using the imagecreatefromstring function. Is that the right way to go about it?

From the PHP manual for imagecreatefromstring ( http://php.net/manual/en/function.imagecreatefromstring.php )

imagecreatefromstring() returns an image identifier representing the image obtained from the given image. These types will be automatically detected if your build of PHP supports them: JPEG, PNG, GIF, WBMP, and GD2.

SVG doesn't appear anywhere in the linked page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM