Circular text around a circle image

2019-08-09 04:34发布

Context:

Tyring to put a SVG path text on top of a circle image.
A square picture is rounded up useing rounded-circle. A SVG path is drawn around it and use to write a text. Resulting in :

enter image description here

Code: https://jsfiddle.net/ghLn4jkt/

<div class="mt-3 row">
    <div class="col-9 CircleThing" style="background-color: coral;">
        <img src="https://via.placeholder.com/500/" alt="contact" class="rounded-circle">
        <svg width="600" height="600">
            <!--Base circle for the text-->
            <!--<circle id="curve" cx="270" cy="270" r="260" stroke="black" stroke-width="3" fill="red" />--> 
            <path id="curve" fill="transparent"
                  d="M 10, 270        
                  a 260,260 0 1,0 520,0
                  a 260,260 0 1,0 -520,0 " />
            <text width="520">
                <textPath xlink:href="#curve"  >
                    aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
                </textPath>
            </text>
        </svg>
    </div>
</div>

Css:

 .CircleThing {
  font-family: Gill Sans Extrabold;
  font-size: 50px;
}

Issue:

In my last try I have multiple issue:
1/. The svg is not on top of the img.
2/. The text start in the bottom left corner while I want it to in the right. To create the path I first did a SVG circle and after reading https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/d deduce it path to be :

M cx, cy
a r,r 0 1,0 (r * 2),0
a r,r 0 1,0 -(r * 2),0

3/. The text is upside down or Inside out. for the top right quatter

1条回答
一夜七次
2楼-- · 2019-08-09 05:21

This is my solution. Please note that I've reversed the #curve for the textPath. Also I've moved the image inside the SVG and rounded with clipPath. This is important if you need to make it responsive.

svg{width:90vh;}
<div class="mt-3 row">
  <div class="col-9 CircleThing" style="background-color: coral;">
    <svg viewBox="-30 -30 600 600" style="background-color: black;">
<defs>
<path id="curve" d="M 10, 270 a 260,260 0 1,1 520,0 a 260,260 0 1,1 -520,0 " />
<clipPath id="clip">
<path d="M 40, 270a 230,230 0 1,0 460,0a 230,230 0 1,0 -460,0 " />
</clipPath>
</defs>
				 
<image xlink:href="https://via.placeholder.com/500/" clip-path="url(#clip)"/>
          
<text fill="white" font-size="40">
<textPath xlink:href="#curve" >
    some words
</textPath>
</text>
</svg>
  </div>
</div>

查看更多
登录 后发表回答