diff options
author | Thanos Apollo <[email protected]> | 2024-06-28 04:22:13 +0300 |
---|---|---|
committer | Thanos Apollo <[email protected]> | 2024-06-28 04:22:25 +0300 |
commit | 37d8110853e7247aa1c8ed41af00edcf298096cb (patch) | |
tree | 59c681eaddf1f42090b2f9fbe39082568bd3a7b5 | |
parent | 0749549451eddf3ccc9a758d9a55a9c67a5d5ea5 (diff) |
gnosis-display-image: Refactor to center image
-rw-r--r-- | gnosis.el | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -366,6 +366,27 @@ This will not be applied to sentences that start with double space." (delete-region end (match-end 0)) (delete-region (match-beginning 0) start)))))))) +(cl-defun gnosis-display-image (id &optional (image 'images)) + "Display image for note ID. + +IMAGE is the image type to display, usually should be either =images' +or =extra-image'. Instead of using =extra-image' post review, prefer +=gnosis-display-extra' which displays the =extra-image' as well. + +Refer to =gnosis-db-schema-extras' for informations on images stored." + (let* ((img (gnosis-get image 'extras `(= id ,id))) + (path-to-image (expand-file-name (or img "") (file-name-as-directory gnosis-images-dir))) + (image (create-image path-to-image 'png nil :width gnosis-image-width :height gnosis-image-height)) + (image-width (car (image-size image t))) + (frame-width (window-text-width))) ;; Width of the current window in columns + (cond ((or (not img) (string-empty-p img)) + (insert "\n\n")) + ((and img (file-exists-p path-to-image)) + (let* ((padding-cols (/ (- frame-width (floor (/ image-width (frame-char-width)))) 2)) + (padding (make-string (max 0 padding-cols) ?\s))) + (insert "\n\n" padding) ;; Insert padding before the image + (insert-image image) + (insert "\n\n")))))) (defun gnosis-display-mcq-options (id) "Display answer options for mcq note ID." |