diff --git a/src/utils.lisp b/src/utils.lisp index 6f5ebe8..ac53f64 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -17,7 +17,8 @@ #:asciify #:slugify #:get-image-dimensions - #:run-bash-command) + #:run-bash-command + #:create-thumbnail) (:documentation "Utilities that do not depend on models.")) (in-package #:utils) @@ -100,3 +101,14 @@ The `FILEPATH' must be already merged with (uiop:run-program command :output :string :ignore-error-status t :error-output :string)) + +(defun create-thumbnail (file-name) + "Runs a Bash command to convert a file to a thumbnail in /storage/media dir. +The file is reduced to 512x512 pixels if bigger than that. A new file +is then created with a 'thumbnail-' pre-fix. This process relies on +Image Magick. So, it must be installed on the system for this function +to operate properly." + (run-bash-command + (format nil "convert ~a -resize 512x512\\> ~a" + (storage:file-exists-p "" "media" file-name) + (storage:make-path "" "media" (format nil "thumbnail-~a" file-name)))))