emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

elpa-admin patch for current ImageMagick


From: Stephen Leake
Subject: elpa-admin patch for current ImageMagick
Date: Fri, 04 Nov 2022 06:00:52 -0700
User-agent: Gnus/5.13 (Gnus v5.13)

In testing my elpa packages, I run 'make build/<pkg>', which is failing
due to the ImageMagick call in elpaa--string-width, because my version
of ImageMagick requires using the "magick" driver. The attached patch
fixes that.

github also ran into this: https://github.com/aheckmann/gm/issues/684

One possibility is to choose a different option during ImageMagick
install, to install the old executables (including "convert"), but
patching the lisp seems more reliable, and more future-proof.

Ok to commit?

-- 
-- Stephe
diff --git a/elpa-admin.el b/elpa-admin.el
index f4a33a2e27..cdbfaa61b3 100644
--- a/elpa-admin.el
+++ b/elpa-admin.el
@@ -872,22 +872,25 @@ SPECS is the list of package specifications."
 (defun elpaa--string-width (str)
   "Determine string width in pixels of STR."
   (with-temp-buffer
-    ;; Current (2021) ImageMagick recommends using the "magick"
-    ;; driver, rather than "convert" directly, but Debian doesn't
-    ;; provide it yet.
-    (elpaa--call (current-buffer)
-                 "convert" "-debug" "annotate" "xc:" "-font" "DejaVu-Sans"
-                 "-pointsize" "110" "-annotate" "0" str "null:")
-    (goto-char (point-min))
-    (if (not (re-search-forward "Metrics:.*?width: \\([0-9]+\\)"))
-        (error "Could not determine string width")
-      (let ((width (string-to-number (match-string 1))))
-        ;; This test aims to catch the case where the font is missing,
-        ;; but it seems it only works in some cases :-(
-        (if (and (> (string-width str) 0) (not (> width 0)))
-            (progn (message "convert:\n%s" (buffer-string))
-                   (error "Could not determine string width"))
-          width)))))
+    ;; ImageMagick 7.1.0 or later requires using the "magick" driver,
+    ;; rather than "convert" directly, but Debian doesn't provide it
+    ;; yet (2021).
+    (let ((args
+           (append (list (current-buffer))
+                   (if (executable-find "magick") '("magick" "convert") 
'("convert"))
+                   (list "-debug" "annotate" "xc:" "-font" "DejaVu-Sans"
+                         "-pointsize" "110" "-annotate" "0" str "null:"))))
+      (apply #'elpaa--call args)
+      (goto-char (point-min))
+      (if (not (re-search-forward "Metrics:.*?width: \\([0-9]+\\)"))
+          (error "Could not determine string width")
+        (let ((width (string-to-number (match-string 1))))
+          ;; This test aims to catch the case where the font is missing,
+          ;; but it seems it only works in some cases :-(
+          (if (and (> (string-width str) 0) (not (> width 0)))
+              (progn (message "convert:\n%s" (buffer-string))
+                     (error "Could not determine string width"))
+            width))))))
 
 (defun elpaa--make-badge (file left right)
   "Make badge svg FILE with LEFT and RIGHT string."

reply via email to

[Prev in Thread] Current Thread [Next in Thread]