gpt4 book ai didi

javascript - PHP 使用 imagecreatefromstring 将 SVG 字符串转换为图像

转载 作者:行者123 更新时间:2023-12-03 08:36:12 25 4
gpt4 key购买 nike

以下 JavaScript 代码会将 SVG 字符串转换为图像 blob,然后可用于在浏览器中显示:

 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);

问题是我希望能够在 PHP 中做同样的事情。我考虑过使用 imagecreatefromstring 函数。这是正确的做法吗?

最佳答案

来自 imagecreatefromstring 的 PHP 手册 ( 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 没有出现在链接页面的任何位置。

关于javascript - PHP 使用 imagecreatefromstring 将 SVG 字符串转换为图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33207471/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com