{"id":1629,"date":"2022-06-08T20:56:17","date_gmt":"2022-06-08T12:56:17","guid":{"rendered":"https:\/\/qishiya.com\/?p=1629"},"modified":"2022-06-08T20:56:17","modified_gmt":"2022-06-08T12:56:17","slug":"php-%e5%a4%84%e7%90%86-svg","status":"publish","type":"post","link":"https:\/\/qishiya.com\/?p=1629","title":{"rendered":"PHP \u5904\u7406 SVG"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5c3a\u7801\u8868\u51c6\u5907\u7528 SVG \u6765\u751f\u6210\uff0c\u56e0\u4e3a SVG \u672c\u8d28\u4e0a\u662f \u4e00\u4e2a xml \u6587\u4ef6\uff0c\u65b9\u4fbf\u6211\u76f4\u63a5\u7528\u4ee3\u7801\u6765\u64cd\u4f5c\u8fd9\u4e2a xml \u6587\u4ef6\uff0c\u5728\u7528 PHP \u5904\u7406 xml \u6587\u4ef6\u7684\u65f6\u5019\uff08\u4e0d\u7528 Golang \u7684\u539f\u56e0\u662f\u6ca1\u6709\u627e\u5230\u76f8\u5e94\u7684\u5e93\uff09\uff0c\u9047\u5230\u51e0\u4e2a\u95ee\u9898\uff0c\u540e\u6765\u53d1\u73b0\u662f\u81ea\u5df1\u6ca1\u6709\u4ed4\u7ec6\u8bfb\u5b98\u65b9\u7684\u8ba8\u8bba\uff0c\u8ba9\u6211\u767d\u5fd9\u6d3b\u4e86 3 \u4e2a\u5c0f\u65f6\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image is-style-default\"><img decoding=\"async\" src=\"https:\/\/tutu-1252436247.cos.ap-beijing.myqcloud.com\/2022\/06\/20220608Qu5M1w.jpg\" alt=\"20220608Qu5M1w\"\/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_61 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #ff6200;color:#ff6200\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #ff6200;color:#ff6200\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/qishiya.com\/?p=1629\/#SimpleXMLElement\" title=\"SimpleXMLElement\">SimpleXMLElement<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/qishiya.com\/?p=1629\/#xml_%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E7%9A%84%E9%97%AE%E9%A2%98\" title=\"xml \u547d\u540d\u7a7a\u95f4\u7684\u95ee\u9898\">xml \u547d\u540d\u7a7a\u95f4\u7684\u95ee\u9898<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/qishiya.com\/?p=1629\/#%E5%88%A0%E9%99%A4%E8%8A%82%E7%82%B9%E7%9A%84%E9%97%AE%E9%A2%98\" title=\"\u5220\u9664\u8282\u70b9\u7684\u95ee\u9898\">\u5220\u9664\u8282\u70b9\u7684\u95ee\u9898<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/qishiya.com\/?p=1629\/#SVG_%E8%BD%AC%E6%8D%A2%E6%88%90_PNG\" title=\"SVG \u8f6c\u6362\u6210 PNG\">SVG \u8f6c\u6362\u6210 PNG<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/qishiya.com\/?p=1629\/#%E9%80%9A%E8%BF%87_PHP_%E6%8A%8A_SVG_%E8%BD%AC%E6%8D%A2%E6%88%90_PNG\" title=\"\u901a\u8fc7 PHP \u628a SVG \u8f6c\u6362\u6210 PNG\">\u901a\u8fc7 PHP \u628a SVG \u8f6c\u6362\u6210 PNG<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/qishiya.com\/?p=1629\/#%E9%80%9A%E8%BF%87%E5%91%BD%E4%BB%A4%E8%A1%8C%E7%9B%B4%E6%8E%A5%E8%BD%AC\" title=\"\u901a\u8fc7\u547d\u4ee4\u884c\u76f4\u63a5\u8f6c\">\u901a\u8fc7\u547d\u4ee4\u884c\u76f4\u63a5\u8f6c<\/a><\/li><\/ul><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SimpleXMLElement\"><\/span>SimpleXMLElement<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"xml_%E5%91%BD%E5%90%8D%E7%A9%BA%E9%97%B4%E7%9A%84%E9%97%AE%E9%A2%98\"><\/span>xml \u547d\u540d\u7a7a\u95f4\u7684\u95ee\u9898<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c xml \u6587\u4ef6\u6709\u58f0\u660e\u547d\u540d\u7a7a\u95f4\uff0c\u8fd9\u4e2a\u5e93\u7684 xpath \u5c31\u4f1a\u5931\u6548\uff0c\u6211\u4e00\u76f4\u4ee5\u4e3a\u662f\u6211\u7684\u4ee3\u7801\u95ee\u9898\uff0c\u540e\u6765\u8bfb\u5230\u6709\u4eba\u53cd\u9988\u76f8\u540c\u7684\u95ee\u9898\uff0c\u624d\u53ef\u4ee5\u5728 SimpleXMLElement \u4e2d\u4f7f\u7528 xpath\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/www.php.net\/manual\/en\/simplexmlelement.xpath.php\">PHP: SimpleXMLElement::xpath &#8211; Manual<\/a> \u8fd9\u4e2a\u6587\u6863\u91cc\u9762\u7684 User Contributed Notes \u5199\u7684\u975e\u5e38\u6e05\u6670\uff0c\u547d\u540d\u7a7a\u95f4\u7684\u95ee\u9898\uff0c\u65e0\u6cd5\u4f7f\u7528 xpath\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E5%88%A0%E9%99%A4%E8%8A%82%E7%82%B9%E7%9A%84%E9%97%AE%E9%A2%98\"><\/span>\u5220\u9664\u8282\u70b9\u7684\u95ee\u9898<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u7684\u9700\u6c42\u662f\u8981\u80fd\u5220\u9664\u67d0 xml \u7684\u67d0\u4e00\u4e2a\u8282\u70b9\uff0c\u7136\u540e\u518d\u751f\u6210 xml \u6587\u6863\uff0c\u5220\u9664\u7684\u8bed\u6cd5\u6bd4\u8f83\u5947\u602a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/stackoverflow.com\/questions\/262351\/remove-a-child-with-a-specific-attribute-in-simplexml-for-php\">xml &#8211; Remove a child with a specific attribute, in SimpleXML for PHP &#8211; Stack Overflow<\/a><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>unset($doc-&gt;xpath('seg&#91;@id=\"A12\"]')&#91;0]-&gt;{0});<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"SVG_%E8%BD%AC%E6%8D%A2%E6%88%90_PNG\"><\/span>SVG \u8f6c\u6362\u6210 PNG<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%80%9A%E8%BF%87_PHP_%E6%8A%8A_SVG_%E8%BD%AC%E6%8D%A2%E6%88%90_PNG\"><\/span>\u901a\u8fc7 PHP \u628a SVG \u8f6c\u6362\u6210 PNG<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e2a\u8981\u5b89\u88c5 imagick \u6269\u5c55\uff0c\u5927\u6982\u7684\u4ee3\u7801\u5982\u4e0b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>        $im = new Imagick();        \n        $svg = file_get_contents($link);        \n        $im-&gt;setBackgroundColor(new ImagickPixel('transparent'));        \n        $im-&gt;readImageBlob($svg);\n        $im-&gt;setImageFormat(\"png32\");        \n        $im-&gt;writeImage($path.$file.\".png\");\n        $im-&gt;clear();\n        $im-&gt;destroy(); <\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/legacy.imagemagick.org\/discourse-server~\/viewtopic4691.html?f=2&amp;t=37312\">Issue in svg to png &#8211; ImageMagick<\/a><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a href=\"https:\/\/stackoverflow.com\/questions\/29994680\/how-to-convert-svg-to-png-using-imagemagick-in-php\">image &#8211; How to convert SVG to PNG using ImageMagick in PHP? &#8211; Stack Overflow<\/a><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E9%80%9A%E8%BF%87%E5%91%BD%E4%BB%A4%E8%A1%8C%E7%9B%B4%E6%8E%A5%E8%BD%AC\"><\/span>\u901a\u8fc7\u547d\u4ee4\u884c\u76f4\u63a5\u8f6c<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>brew install imagemagick --with-librsvg\n\nconvert    801.svg 801.png\n\nconvert -size 800x800   801.svg 801.png<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5c3a\u7801\u8868\u51c6\u5907\u7528 SVG \u6765\u751f\u6210\uff0c\u56e0\u4e3a SVG \u672c\u8d28\u4e0a\u662f \u4e00\u4e2a xml \u6587\u4ef6\uff0c\u65b9\u4fbf\u6211\u76f4\u63a5\u7528\u4ee3\u7801\u6765\u64cd\u4f5c\u8fd9\u4e2a xml \u6587\u4ef6\uff0c\u5728\u7528 PHP \u5904\u7406 xml \u6587\u4ef6\u7684\u65f6\u5019\uff08\u4e0d\u7528 Golang \u7684\u539f\u56e0\u662f\u6ca1\u6709\u627e\u5230\u76f8\u5e94\u7684\u5e93\uff09\uff0c\u9047\u5230\u51e0\u4e2a\u95ee\u9898\uff0c\u540e\u6765\u53d1\u73b0\u662f\u81ea\u5df1\u6ca1\u6709\u4ed4\u7ec6 &#8230; <a title=\"PHP \u5904\u7406 SVG\" class=\"read-more\" href=\"https:\/\/qishiya.com\/?p=1629\" aria-label=\"\u66f4\u591a PHP \u5904\u7406 SVG\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"templates\/template-full-width.php","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1629","post","type-post","status-publish","format-standard","hentry","category-5"],"_links":{"self":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/1629","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1629"}],"version-history":[{"count":0,"href":"https:\/\/qishiya.com\/index.php?rest_route=\/wp\/v2\/posts\/1629\/revisions"}],"wp:attachment":[{"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1629"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1629"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qishiya.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1629"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}