如题,create-image
能否为图片设置圆角属性?我在 info 里好像没找到,感觉应该是可以的。
或者,用什么方式能在 buffer 插入可设置圆角的图片?
可以用 SVG
原理是绘制圆角矩形,然后给图片作为蒙版
(require 'svg)
(let* ((width 690)
(height 1188)
(svg (svg-create width height))
(cpath (svg-clip-path svg :id "clip")))
(svg-rectangle cpath 0 0 width height :rx 60)
(svg-embed
svg
(expand-file-name "~/Desktop/v2-9bdc1af964fb57bee4d65ccbb4a51352_r.jpg")
"image/jpeg" nil
:width (format "%spx" width) :height (format "%spx" height)
:clip-path "url(#clip)")
(svg-insert-image svg))
效果图
2 个赞
效果挺好,哈哈
(defun netease-cloud-music--insert-avatar (url buffer)
"The function to insert user's avatar.
URL is avatar's url.
BUFFER is the comment buffer."
(let ((buf (url-retrieve-synchronously url)))
(unwind-protect
(let ((data (with-current-buffer buf
(goto-char (point-min))
(search-forward "\n\n")
(buffer-substring (point) (point-max)))))
(with-current-buffer buffer
(let* ((width (round (* (frame-width) 0.5)))
(svg (svg-create width width))
(cpath (svg-clip-path svg :id "clip")))
(svg-rectangle cpath 0 0 width width
:rx (* 0.5 width))
(svg-embed svg data "image/jpeg" t
:width (format "%dpx" width)
:height (format "%dpx" width)
:clip-path "url(#clip)")
(svg-insert-image svg))))
(kill-buffer buf))))
不过我有个问题,一开始用了 svg-create
定义了宽度和高度,后面为什么还要在嵌入的时候再设置?
是因为前者单位不是像素?
SVG大小是画布的大小,元素可以自己指定自己的大小和在画布的位置。