![](/img/trans.png)
[英]How to pass a python wordcloud element to svgwrite method to generate a svg of the wordcloud?
[英]How to insert image into a circle element of svg? (Python: svgwrite)
我知道如何在普通 SVG 文件上執行此任務,但我在 python 3.7 中使用svgwrite
包,但我不知道如何執行此操作。 遺憾的是,網站文檔沒有足夠准確地涵蓋這個主題......
image.add(image.ellipse(center=(half_x, half_y), r=(340, 340), fill=line_color, cx=50, cy=50, rx=80, ry=60, stroke="rgb(255,255,255)", opacity=0.3, stroke_width="0.5", id="img-container"))
image.add(image.image(href="https://images.pexels.com/photos/799443/pexels-photo-799443.jpeg", insert=None, size=("100%","100%"), clip_path="img-container"))
我只想在我的 SVG 文件中有一個圓形圖像。 如果您知道任何更好的方法,請告訴我!
編輯:此外,當我想使用clipPath
出現以下錯誤:
ValueError: Invalid children 'image' for svg-element <clipPath>.
我用mask
來完成這個任務。 首先,添加一個 id 為wrapper
的 mask 元素,然后添加一個 circle 元素作為 mask 的子元素。 最后一個技巧是向圖像元素添加掩碼屬性,如url(#bg_wrapper)
。
image = svgwrite.Drawing(output_file, size=(str(width)+'mm', str(height)+'mm'))
# Custom image
mask = image.defs.add(image.mask(id="bg_wrapper"))
mask.add(image.circle(center=(half_x, half_y), r=335, fill=line_color, opacity=".4"))
image.add(image.image(href="image.jpeg", size=("100%", "100%"), mask="url(#bg_wrapper)"))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.