为了账号安全,请及时绑定邮箱和手机立即绑定

如何在php中将徽标(徽标是.png格式的图像)嵌入到另一个图像(.svg格式的图像)中

如何在php中将徽标(徽标是.png格式的图像)嵌入到另一个图像(.svg格式的图像)中

PHP
慕桂英3389331 2022-07-22 16:04:22
我想将徽标(.png)集成到另一个图像(.svg)文件中。我想知道是否可以使用php?我正在使用这个,但这不起作用。<image x="0" y="0" width="10" height="10" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="https://bellard.org/bpg/2.png" onclick="this.setAttributeNS('http://www.w3.org/1999/xlink', 'href', 'http://pngimg.com/uploads/polar_bear/polar_bear_PNG23514.png')">   </image>我已将 .osm 文件转换为 .svg,现在当我在 SVG 文件中手动输入图像标签时,我必须在该 .svg 文件中集成一个徽标,该 SVG 文件显示在 chrome 上但未反映在图像查看器上。那么有什么方法或文档吗?谢谢您的帮助。
查看完整描述

1 回答

?
慕莱坞森

TA贡献1810条经验 获得超4个赞

公共函数 imageEmbed(请求 $request){


$file = $request->file('file');

$svg_data = file_get_contents($file);

$svg = new \SimpleXMLElement($svg_data, LIBXML_NOEMPTYTAG);

$svg->registerXPathNamespace('svg', 'http://www.w3.org/2000/svg');


$g_res= $svg->addChild("text", "COPYRIGHT @ 2020");

$g_res->addAttribute("x", "150");

$g_res->addAttribute("y", "220");

$g_res->addAttribute("font-family", "Verdana");

$g_res->addAttribute("font-size", "10");

$g_res->addAttribute("fill", "red");


$g_res = $svg->addChild("image","1");

$g_res->addAttribute("x", "0");

$g_res->addAttribute("y", "0");

$g_res->addAttribute("width", "50");

$g_res->addAttribute("height", "50");

$g_res->addAttribute("xlink", 'http://www.w3.org/1999/xlink');

$g_res['xlink:href'] = "enter your base64 image here.";

$g_res->addAttribute("onclick", "this.setAttributeNS('http://www.w3.org/1999/xlink')");


$dom_res = dom_import_simplexml($g_res);

$dom_svg = dom_import_simplexml($svg);

$dom_svg->formatOutput = true;

$dom_svg->appendChild($dom_res);


echo $svg->saveXML(public_path('image/test.svg'));

}


查看完整回答
反对 回复 2022-07-22
  • 1 回答
  • 0 关注
  • 159 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号