From 9a50938c0dd47c4f6f40527610b2e1722297ff80 Mon Sep 17 00:00:00 2001 From: Craig Oates Date: Sun, 18 Sep 2022 23:06:07 +0100 Subject: [PATCH] implement get-image-dimensions function in utils package. --- src/utils.lisp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/utils.lisp b/src/utils.lisp index 7d09b37..6f5ebe8 100644 --- a/src/utils.lisp +++ b/src/utils.lisp @@ -15,7 +15,9 @@ #:get-and-reset-alert #:checkbox-to-bool #:asciify - #:slugify) + #:slugify + #:get-image-dimensions + #:run-bash-command) (:documentation "Utilities that do not depend on models.")) (in-package #:utils) @@ -33,6 +35,7 @@ (read-from-string key)) :collect value)) +;; PORT CODE TO NO LONGER CALL THIS VERSION OF THE FUNCTION (MOVED TO VALIDATION PACKAGE). (defun string-is-nil-or-empty? (string-to-test) "Tests to see if `STRING-TO-TEST' is empty of just whitespace. This is essentially the 'IsNullOrWhiteSpace' function I use in C#. It @@ -80,3 +83,20 @@ THIS FUNCTION." (cond ((or (string= "checked" value) (string= "on" value)) +true+) ((or (string= "off" value) (null value)) +false+) ((null value) +false+))) + +(defun get-image-dimensions (filepath) + "Uses Image Magick (via Bash) to get the resolution of an image as 'WxH'. +The `FILEPATH' must be already merged with +`ritherdon-archive.config::*application-root*' before you call this function." + (let* ((command + (format nil "identify -format \"%wx%h\" ~a" filepath)) + (out-message (uiop:run-program command :output :string + :ignore-error-status t + :error-output :string))) + out-message)) + +(defun run-bash-command (command) + "Runs the Bash command." + (uiop:run-program command :output :string + :ignore-error-status t + :error-output :string))