From 79231cf0836b330e410ea6bc71839c8b04d3feb8 Mon Sep 17 00:00:00 2001 From: Miranda Marquez Date: Mon, 30 Sep 2024 19:38:38 -0800 Subject: [PATCH] multi line images? mayhaps? --- img-strips.el | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 img-strips.el diff --git a/img-strips.el b/img-strips.el new file mode 100644 index 0000000..a4eddbe --- /dev/null +++ b/img-strips.el @@ -0,0 +1,100 @@ +;; cut an image into wafer thin strips and display one per line. this streamlines box renderers. + +(setq jaypeg "~/.local/share/backgrounds/mojave.jpg") +(setq img-strips-cache-dir "~/.cache/img-strips/") + +;; https://dev.to/ko31/using-imagemagick-to-easily-split-an-image-file-13hb +(defun img-strip-slice (file lines) + "Use background ImageMagick to cut FILE into strips. LINES is how many. + +Return the output path." + (let* ((height-% (/ 100 lines)) + (file-title (file-name-base file)) + (cache-dir (expand-file-name file-title img-strips-cache-dir))) + (make-directory cache-dir 'p) + (shell-command + (format "convert -crop 100%%x%s%% %s %s/img-strip.png" + height-% + file + cache-dir + )) + cache-dir + )) +(img-strip-slice "~/rena.webp" 5) +(img-strip-slice "~/.face" 4) + +" +%%rena/img-strip-0%% +%%rena/img-strip-1%% +%%rena/img-strip-2%% +%%rena/img-strip-3%% +%%rena/img-strip-4%% +" +" +%%.face/img-strip-0%% +%%.face/img-strip-1%% +%%.face/img-strip-2%% +%%.face/img-strip-3%% +" + + +(defun img-strip-cache-from-placeholder (placeholder) + ;; ;; doesn't find img-strip-0 + ;; (remove 0 (mapcar #'string-to-number + ;; (split-string placeholder (rx (or "%" "-")) 'omit))) + (format "%s/%s.png" + img-strips-cache-dir + (string-trim placeholder "%%" "%%"))) +;; (img-strip-cache-from-placeholder "%%rena/img-strip-1%%") +(defvar img-strip-placeholder-rx (rx (group-n 1 "%%" (+ (or alnum ".")) "/img-strip-" num "%%"))) +(defun next-img-strip-overlay (&optional limit) + "like `next-emoji-overlay' but for img-strips." + (while (re-search-forward img-strip-placeholder-rx limit t) + (let* ((beg (match-beginning 0)) + (end (match-end 0)) + (placeholder (match-string 1)) + (cache (img-strip-cache-from-placeholder placeholder))) + (unless (mir/overlay-already-at-p beg end) + (if cache + (let ((img (create-image cache + 'png + nil + :height (window-font-height) + :ascent 'center)) + (ov (make-overlay beg end))) + (overlay-put ov 'display img) + (overlay-put ov 'org-image-overlay t) + (overlay-put ov 'modification-hooks + (list 'org-display-inline-remove-overlay)))))))) + +;; thank you zyd +(defun number-in-string2 (s) + (let ((numbers [?0 ?1 ?2 ?3 ?4 ?5 ?6 ?7 ?8 ?9]) + ) + (cl-position-if + (lambda (x) + (seq-contains-p numbers x)) + s))) +;; (number-in-string2 "file12.mp0") + +(defun insert-img-as-strips (image lines) + "Render IMAGE as strips. How many? LINES number of strips." + (interactive "fInsert image: \nnNumber of lines: ") + (let ((name (file-name-base image))) + (img-strip-slice image lines) + (--map (insert (format "%%%%%s/img-strip-%s%%%%\n" name it)) + (number-sequence 0 (- lines 1))))) + +" +%%mojave/img-strip-0%% +%%mojave/img-strip-1%% +%%mojave/img-strip-2%% +%%mojave/img-strip-3%% +%%mojave/img-strip-4%% +%%mojave/img-strip-5%% +%%mojave/img-strip-6%% +%%mojave/img-strip-7%% +%%mojave/img-strip-8%% +" + +;;; img-strips.el ends here