complete-computing-environment/screenshot-svg.org

29 lines
1019 B
Org Mode

:PROPERTIES:
:ID: 20210831T122511.404297
:ROAM_ALIASES: https://reddit.com/r/emacs/comments/idz35e/emacs_27_can_take_svg_screenshots_of_itself/
:END:
#+title: Capturing an Emacs SVG screenshot
#+ARCOLOGY_KEY: cce/emacs-svg-screenshot
#+ARCOLOGY_ALLOW_CRAWL: t
#+begin_example
As mentioned by Clement on Mickey's blog post, Emacs 27.1 can use Cairo to take SVG screenshots of itself. The result is, of course, resizeable without aliasing, and looks great in a Web browser.
#+end_example
#+ARROYO_EMACS_MODULE: svg-screenshot
#+ARROYO_MODULE_WANTS: cce/configure_packaging.org
#+begin_src emacs-lisp :tangle svg-screenshot.el :results none
(defun screenshot-svg ()
"Save a screenshot of the current frame as an SVG image.
Saves to a temp file and puts the filename in the kill ring."
(interactive)
(let* ((filename (make-temp-file "Emacs" nil ".svg"))
(data (x-export-frames nil 'svg)))
(with-temp-file filename
(insert data))
(kill-new filename)
(message filename)))
#+end_src