简体   繁体   English

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

[英]How to embed a logo ( logo is image in .png format ) into another image ( image in .svg format) in php

I want to integrate a logo (.png) in a another image(.svg) file.我想将徽标 (.png) 集成到另一个图像 (.svg) 文件中。 I would like to know is it possible using php?我想知道是否可以使用php?

I am using this , but this is not working .我正在使用它,但这不起作用。

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

I have converted a .osm file into .svg and now I have to integrate a logo inside that .svg file when I enter an image tag manually inside that SVG file that is showing on chrome but not reflected on image viewer.我已将 .osm 文件转换为 .svg,现在我必须在该 .svg 文件中集成徽标,当我在该 SVG 文件中手动输入图像标签时,该 SVG 文件显示在 chrome 上但未反映在图像查看器上。 So is there any way or documentation for this?那么有什么方法或文档吗?

Thank you for your help.感谢您的帮助。

public function imageEmmbed(Request $request){公共函数图像嵌入(请求 $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'));

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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