微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

cairosvg 生成一半渲染的 png 输出

如何解决cairosvg 生成一半渲染的 png 输出

我正在尝试将 verovio 工具包在 svg 中呈现的乐谱转换为 png。使用基本的“正常”svgs,这可以正常工作。但是 verovio svg 不知何故看起来只渲染了一半(example is here)。我对 svg 没有经验,但也许我只是弄错了一些参数,或者是 svg 导致了问题?

生成上述 png 的 python 代码如下所示:

import cairosvg

s = cairosvg.svg2png(svgString)
with open('myscore.png','wb') as f:
    f.write(s)

感谢您的任何提示或建议。

我也将 verovio 渲染的 svgString 内容在这里

<svg width="675px" height="216px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:mei="http://www.music-encoding.org/ns/mei" overflow="visible">
   <desc>Engraved by Verovio 3.3.0-e62c7d5</desc>
   <defs>
      <symbol id="E050" viewBox="0 0 1000 1000" overflow="inherit">
         <path transform="scale(1,-1)" d="M441 -245c-23 -4 -48 -6 -76 -6c-59 0 -102 7 -130 20c-88 42 -150 93 -187 154c-26 44 -43 103 -48 176c0 6 -1 13 -1 19c0 54 15 111 45 170c29 57 65 106 110 148s96 85 153 127c-3 16 -8 46 -13 92c-4 43 -5 73 -5 89c0 117 16 172 69 257c34 54 64 82 89 82 c21 0 43 -30 69 -92s39 -115 41 -159v-15c0 -109 -21 -162 -67 -241c-13 -20 -63 -90 -98 -118c-13 -9 -25 -19 -37 -29l31 -181c8 1 18 2 28 2c58 0 102 -12 133 -35c59 -43 92 -104 98 -184c1 -7 1 -15 1 -22c0 -123 -87 -209 -181 -248c8 -57 17 -110 25 -162 c5 -31 6 -58 6 -80c0 -30 -5 -53 -14 -70c-35 -64 -88 -99 -158 -103c-5 0 -11 -1 -16 -1c-37 0 -72 10 -108 27c-50 24 -77 59 -80 105v11c0 29 7 55 20 76c18 28 45 42 79 44h6c49 0 93 -42 97 -87v-9c0 -51 -34 -86 -105 -106c17 -24 51 -36 102 -36c62 0 116 43 140 85 c9 16 13 41 13 74c0 20 -1 42 -5 67c-8 53 -18 106 -26 159zM461 939c-95 0 -135 -175 -135 -286c0 -24 2 -48 5 -71c50 39 92 82 127 128c40 53 60 100 60 140v8c-4 53 -22 81 -55 81h-2zM406 119l54 -326c73 25 110 78 110 161c0 7 0 15 -1 23c-7 95 -57 142 -151 142h-12 zM382 117c-72 -2 -128 -47 -128 -120v-7c2 -46 43 -99 75 -115c-3 -2 -7 -5 -10 -10c-70 33 -116 88 -123 172v11c0 68 44 126 88 159c23 17 49 29 78 36l-29 170c-21 -13 -52 -37 -92 -73c-50 -44 -86 -84 -109 -119c-45 -69 -67 -130 -67 -182v-13c5 -68 35 -127 93 -176 s125 -73 203 -73c25 0 50 3 75 9c-19 111 -36 221 -54 331z" />
      </symbol>
      <symbol id="E062" viewBox="0 0 1000 1000" overflow="inherit">
         <path transform="scale(1,-1)" d="M158 96c51 0 73 -14 88 -49l16 -39c0 -17 -2 -30 -7 -40c-3 -11 -10 -21 -19 -31c-17 -18 -49 -43 -84 -43c-55 0 -77 13 -112 44c-24 21 -35 55 -35 100c0 46 14 81 32 112c30 52 71 79 137 93l36 6l26 2c154 0 235 -68 274 -182c11 -32 18 -68 18 -107 c0 -103 -26 -182 -68 -250c-89 -145 -234 -230 -412 -288l-30 -5c-9 0 -14 3 -14 8c3 10 5 11 10 16c35 15 70 30 96 44l78 43c96 57 162 136 197 258c9 33 17 60 22 100c3 22 5 35 6 39c-7 69 -16 115 -23 140s-4 22 -16 40c-8 12 -19 23 -31 34c-24 21 -62 44 -118 44 c-48 0 -84 -8 -113 -28c-28 -19 -42 -44 -42 -73v-16c2 -5 3 -9 4 -11c24 22 52 39 84 39zM585 -118c0 32 23 58 57 58c18 0 33 -6 40 -18c9 -15 16 -18 16 -40c0 -9 -2 -16 -5 -21c-6 -19 -27 -37 -51 -37c-34 0 -57 26 -57 58zM642 177c31 0 56 -27 56 -58 c0 -30 -25 -58 -56 -58l-23 3c-19 7 -34 32 -34 55l3 23c9 20 28 35 54 35z" />
      </symbol>
      <symbol id="E08A" viewBox="0 0 1000 1000" overflow="inherit">
         <path transform="scale(1,-1)" d="M340 179c-9 24 -56 41 -89 41c-46 0 -81 -28 -100 -58c-17 -28 -25 -78 -25 -150c0 -65 2 -111 8 -135c8 -31 18 -49 40 -67c20 -17 43 -25 70 -25c54 0 92 36 115 75c14 25 23 54 28 88h27c0 -63 -24 -105 -58 -141c-35 -38 -82 -56 -140 -56c-45 0 -83 13 -115 39 c-57 45 -101 130 -101 226c0 59 33 127 68 163c36 37 97 72 160 72c36 0 93 -21 121 -40c11 -8 23 -17 33 -30c19 -23 27 -48 27 -76c0 -51 -35 -88 -86 -88c-43 0 -76 27 -76 68c0 26 7 35 21 51c15 17 32 27 58 32c7 2 14 7 14 11z" />
      </symbol>
      <symbol id="E0A2" viewBox="0 0 1000 1000" overflow="inherit">
         <path transform="scale(1,-1)" d="M198 133c102 0 207 -45 207 -133c0 -92 -98 -133 -207 -133c-101 0 -198 46 -198 133c0 88 93 133 198 133zM293 -21c0 14 -3 29 -8 44c-7 20 -18 38 -33 54c-20 21 -43 31 -68 31l-20 -2c-15 -5 -27 -14 -36 -28c-4 -9 -6 -17 -8 -24s-3 -16 -3 -27c0 -15 3 -34 9 -57 s18 -41 34 -55c15 -15 36 -23 62 -23c4 0 10 1 18 2c19 5 32 15 40 30s13 34 13 55z" />
      </symbol>
      <symbol id="E262" viewBox="0 0 1000 1000" overflow="inherit">
         <path transform="scale(1,-1)" d="M136 186v169h17v-164l44 14v-91l-44 -14v-165l44 12v-91l-44 -13v-155h-17v150l-76 -22v-155h-17v149l-43 -13v90l43 14v167l-43 -14v92l43 13v169h17v-163zM60 73v-167l76 22v168z" />
      </symbol>
   </defs>
   <style type="text/css">g.page-margin{font-family:Times;} g.reh,g.tempo{font-weight:bold;} g.dir,g.dynam,g.mNum{font-style:italic;} g.label{font-weight:normal;}</style>
   <svg class="deFinition-scale" color="black" viewBox="0 0 15000 4800">
      <g class="page-margin" transform="translate(500,500)">
         <g id="system-0000001941505672" class="system">
            <path d="M13 255 L13 2775" stroke="currentColor" stroke-width="27" />
            <g id="section-0000001463337835" class="section boundaryStart" />
            <g id="pb-0000001336267401" class="pb" />
            <g id="measure-0000001159844410" class="measure">
               <g id="staff-0000000091667497" class="staff">
                  <path d="M0 255 L3441 255" stroke="currentColor" stroke-width="13" />
                  <path d="M0 435 L3441 435" stroke="currentColor" stroke-width="13" />
                  <path d="M0 615 L3441 615" stroke="currentColor" stroke-width="13" />
                  <path d="M0 795 L3441 795" stroke="currentColor" stroke-width="13" />
                  <path d="M0 975 L3441 975" stroke="currentColor" stroke-width="13" />
                  <g id="clef-0000000319074709" class="clef">
                     <use xlink:href="#E050" x="90" y="795" height="720px" width="720px" />
                  </g>
                  <g id="keysig-0000000421967604" class="keySig">
                     <use xlink:href="#E262" x="771" y="255" height="720px" width="720px" />
                     <use xlink:href="#E262" x="949" y="525" height="720px" width="720px" />
                  </g>
                  <g id="msig-0000001018518034" class="meterSig">
                     <use xlink:href="#E08A" x="1270" y="615" height="720px" width="720px" />
                  </g>
                  <g id="layer-0000000909847180" class="layer">
                     <g id="mSpace-0000001300295425" class="mSpace" />
                  </g>
               </g>
               <g id="staff-0000000129334338" class="staff">
                  <path d="M0 2055 L3441 2055" stroke="currentColor" stroke-width="13" />
                  <path d="M0 2235 L3441 2235" stroke="currentColor" stroke-width="13" />
                  <path d="M0 2415 L3441 2415" stroke="currentColor" stroke-width="13" />
                  <path d="M0 2595 L3441 2595" stroke="currentColor" stroke-width="13" />
                  <path d="M0 2775 L3441 2775" stroke="currentColor" stroke-width="13" />
                  <g id="clef-0000000640447201" class="clef">
                     <use xlink:href="#E062" x="90" y="2235" height="720px" width="720px" />
                  </g>
                  <g id="keysig-0000000808068443" class="keySig">
                     <use xlink:href="#E262" x="771" y="2235" height="720px" width="720px" />
                     <use xlink:href="#E262" x="949" y="2505" height="720px" width="720px" />
                  </g>
                  <g id="msig-0000000519737873" class="meterSig">
                     <use xlink:href="#E08A" x="1270" y="2415" height="720px" width="720px" />
                  </g>
                  <g id="layer-0000000468768002" class="layer">
                     <g id="note-0000001613792418" class="note">
                        <g class="notehead">
                           <use xlink:href="#E0A2" x="1838" y="2415" height="720px" width="720px" />
                        </g>
                     </g>
                  </g>
               </g>
               <g id="bline-0000000012782771" class="barLineAttr">
                  <path d="M3428 975 L3428 255" stroke="currentColor" stroke-width="27" />
                  <path d="M3428 2775 L3428 2055" stroke="currentColor" stroke-width="27" />
               </g>
            </g>
            <g id="measure-0000001271616103" class="measure">
               <g id="staff-0000000798561613" class="staff">
                  <path d="M3441 255 L5224 255" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 435 L5224 435" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 615 L5224 615" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 795 L5224 795" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 975 L5224 975" stroke="currentColor" stroke-width="13" />
                  <g id="layer-0000001799719588" class="layer">
                     <g id="mSpace-0000001897195361" class="mSpace" />
                  </g>
               </g>
               <g id="staff-0000001348127086" class="staff">
                  <path d="M3441 2055 L5224 2055" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 2235 L5224 2235" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 2415 L5224 2415" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 2595 L5224 2595" stroke="currentColor" stroke-width="13" />
                  <path d="M3441 2775 L5224 2775" stroke="currentColor" stroke-width="13" />
                  <g id="layer-0000002019458552" class="layer">
                     <g id="note-0000000060842629" class="note">
                        <g class="notehead">
                           <use xlink:href="#E0A2" x="3621" y="2235" height="720px" width="720px" />
                        </g>
                        <g id="accid-0000000379849631" class="accid" />
                        <g id="verse-0000001811349333" class="verse">
                           <title class="labelAttr">1</title>
                           <g id="syl-0000000620059859" class="syl">
                              <text x="3531" y="3267" font-size="0px">
                                 <tspan id="text-0000001755394969" class="text">
                                    <tspan font-size="405px" class="text">6</tspan>
                                 </tspan>
                              </text>
                           </g>
                        </g>
                        <g id="verse-0000000792901497" class="verse">
                           <title class="labelAttr">2</title>
                           <g id="syl-0000001159430444" class="syl">
                              <text x="3531" y="3667" font-size="0px">
                                 <tspan id="text-0000000280859430" class="text">
                                    <tspan font-size="405px" class="text">b5</tspan>
                                 </tspan>
                              </text>
                           </g>
                        </g>
                     </g>
                  </g>
               </g>
               <g id="bline-0000001563991099" class="barLineAttr">
                  <path d="M5211 975 L5211 255" stroke="currentColor" stroke-width="27" />
                  <path d="M5211 2775 L5211 2055" stroke="currentColor" stroke-width="27" />
               </g>
            </g>
            <g id="measure-0000000325241671" class="measure">
               <g id="staff-0000000297628127" class="staff">
                  <path d="M5224 255 L7106 255" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 435 L7106 435" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 615 L7106 615" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 795 L7106 795" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 975 L7106 975" stroke="currentColor" stroke-width="13" />
                  <g id="layer-0000000746516626" class="layer">
                     <g id="mSpace-0000001709696059" class="mSpace" />
                  </g>
               </g>
               <g id="staff-0000002102365359" class="staff">
                  <path d="M5224 2055 L7106 2055" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 2235 L7106 2235" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 2415 L7106 2415" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 2595 L7106 2595" stroke="currentColor" stroke-width="13" />
                  <path d="M5224 2775 L7106 2775" stroke="currentColor" stroke-width="13" />
                  <g id="layer-0000001906144622" class="layer">
                     <g id="note-0000000411616008" class="note">
                        <g class="notehead">
                           <use xlink:href="#E0A2" x="5404" y="2145" height="720px" width="720px" />
                        </g>
                     </g>
                  </g>
               </g>
               <g id="bline-0000001926709320" class="barLineAttr">
                  <path d="M6994 975 L6994 255" stroke="currentColor" stroke-width="27" />
                  <path d="M7093 975 L7093 255" stroke="currentColor" stroke-width="27" />
                  <path d="M6994 2775 L6994 2055" stroke="currentColor" stroke-width="27" />
                  <path d="M7093 2775 L7093 2055" stroke="currentColor" stroke-width="27" />
               </g>
            </g>
            <g id="bdend-0000001566348176" class="boundaryEnd section-0000001463337835" />
         </g>
      </g>
   </svg>
</svg>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。