Eric S Fraga <[email protected]> writes:
> [email protected] (François Pinard) writes:
> Thanks! However, if I give it a directory name, the function fails
> with "Cannot create image file" in the mini-buffer. [...] In
> summary, if I give it an existing file name, that works; if I give it
> a non-existing file name, that also works. It only fails if I give it
> a directory.
Hi, Eric. Sorry. Here is a quick correction for that problem. This is
only this week that I plan to use that function for actual work; last
week was rather an exploration of the capability of various tools. Of
course, do not hesitate if you see that I goofed elsewhere! :-).
Thanks, François
(defun fp-org-image (name)
"Insert a link to an already existing image, or else to a screenshot.
The screenshot is either taken to the given non-existing file name,
or added into the given directory, defaulting to the current one."
;; FIXME: Should limit to '("pdf" "jpeg" "jpg" "png" "ps" "eps")
;; which is org-export-latex-inline-image-extensions.
(interactive "GImage name? ")
(when (file-directory-p name)
(setq name (concat
(make-temp-name
(concat (file-name-as-directory name)
(subst-char-in-string
"." "-"
(file-name-sans-extension
(file-name-nondirectory
(buffer-file-name))))))
".png")))
(unless (file-exists-p name)
(unless (file-writable-p name)
(debug)
(error "Cannot create image file"))
(message "Taking screenshot...")
(call-process "import" nil nil nil name)
(message "Taking screenshot...done"))
(insert (concat "[[" name "]]"))
(org-display-inline-images))