Last active
December 1, 2023 04:03
-
-
Save peixian/a928a7a169ed5a4c3ec908bd84394374 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun format-gps-coordinates (latitude longitude) | |
"Format latitude and longitude into a human-readable string." | |
(let ((lat-hem (if (string-match "S" latitude) "S" "N")) | |
(long-hem (if (string-match "W" longitude) "W" "E"))) | |
(format "%s, %s" | |
(replace-regexp-in-string " deg.*" "" latitude) | |
(replace-regexp-in-string " deg.*" "" longitude)))) | |
(defun extract-exif-geolocation (file) | |
"Extract and format the EXIF geolocation data from an image file." | |
(let ((exif-output (shell-command-to-string (format "exiftool -gpslatitude -gpslongitude -n -T %s" (shell-quote-argument file))))) | |
(if (string-match "\\([-+]?[0-9.]+\\)[ \t]+\\([-+]?[0-9.]+\\)" exif-output) | |
(let ((latitude (match-string 1 exif-output)) | |
(longitude (match-string 2 exif-output))) | |
(format-gps-coordinates latitude longitude)) | |
"No geolocation data"))) | |
(defun generate-org-gallery-with-exif () | |
"Generate an Org mode gallery file with EXIF geolocation data." | |
(interactive) | |
(let ((image-dir "~/code/writing/assets/shrines") | |
(org-file "~/code/writing/blog/shrines.org") | |
(files (directory-files "~/code/writing/assets/shrines" t "\\(jpg\\|jpeg\\|png\\|gif\\)$"))) | |
(with-temp-file org-file | |
(insert "#+TITLE: Shrines\n") | |
(insert "#+AUTHOR: Peixian\n") | |
(insert "#+DATE: 2023-11-26\n") | |
(insert "#+URI: /shrines/\n\n") | |
(insert "Photographs of various shrines I've seen. A shrine here is basically anything I consider to have spiritual significance.\n\n") | |
(dolist (file files) | |
(unless (or (string-equal (file-name-nondirectory file) ".") | |
(string-equal (file-name-nondirectory file) "..")) | |
(let ((exif-data (extract-exif-geolocation file))) | |
(insert (format "[[file:../assets/shrines/%s]]\n" (file-relative-name file image-dir))) | |
(insert (format "</%s/>\n\n" exif-data)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment