Subject: bug#63427: gdk-pixbuf unable to recognize image formats (JPG, PNG, etc.)

From: "pelzflorian (Florian Pelz)" <[email-masked]>
Date: Wed, 15 Jan 2025 15:28:17 +0100

Thank you Maxim for waking up the bug and giving an essential hint,
because I did not understand the bug anymore.

Indeed, without wrapping GDK_PIXBUF_MODULE_FILE as in my patch

guix shell --pure viewnior gdk-pixbuf webp-pixbuf-loader

does open webp files fine.

Wrapping it with the attached patch,

guix shell --pure viewnior

also opens webp files fine, but only after I have added
webp-pixbuf-loader to viewnior’s inputs.

But wrapping inhibits webp-pixbuf-loader when I don’t add it to inputs
even with

guix shell --pure viewnior gdk-pixbuf webp-pixbuf-loader

So wrapping apparently hard-codes which input formats there are.

Notably librsvg exceptionally does not need to be added explicitly.

Is it better to wrap viewnior and hard-code the supported image formats,
as I wanted, so installing only viewnior is enough?

Or better drop the attached patch and users need to install gdk-pixbuf
webp-pixbuf-loader as well?

I tend to prefer to wrap viewnior.

Regards,
Florian
>From 54746d297c7e3de10001a270867beb031afca0df Mon Sep 17 00:00:00 2001
Message-ID: <547[email-masked]>
From: Florian Pelz <[email-masked]>
Date: Sat, 13 May 2023 12:33:26 +0200
Subject: [PATCH] gnu: viewnior: Support image formats out of the box.

* gnu/packages/image-viewers.scm (viewnior)
[inputs]: TODO Add 'librsvg-for-system', 'webp-pixbuf-loader'.
[arguments]: Enable 'glib-or-gtk?' to make available
GDK_PIXBUF_MODULE_FILE.  Wrap viewnior to use it instead
of the image loaders installed by the user.

Change-Id: I86b7c2845af2fc1d3fdf4032b2208493a6868546
---
 gnu/packages/image-viewers.scm | 31 +++++++++++++++++++++++--------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/gnu/packages/image-viewers.scm b/gnu/packages/image-viewers.scm
index cb4e903f39..8c679ac2fb 100644
--- a/gnu/packages/image-viewers.scm
+++ b/gnu/packages/image-viewers.scm
@@ -27,6 +27,7 @@
 ;;; Copyright © 2022, 2023 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2022 Tomasz Jeneralczyk <[email-masked]>
 ;;; Copyright © 2022 Cairn <[email-masked]>
+;;; Copyright © 2023 Florian Pelz <[email-masked]>
 ;;; Copyright © 2024 Artyom V. Poptsov <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
@@ -427,13 +428,24 @@ (define-public viewnior
         (base32 "14qvx1wajncd5ab0207274cwk32f4ipfnlaci6phmah0cwra2did"))))
     (build-system meson-build-system)
     (arguments
-     '(#:phases (modify-phases %standard-phases
-                  (add-after 'unpack 'patch-source
-                    (lambda _
-                      ;; Don't create 'icon-theme.cache'
-                      (substitute* "meson.build"
-                        (("meson.add_install_script*") "")))))
-       #:tests? #f))                    ;no tests
+     (list #:glib-or-gtk? #t
+           #:phases
+           #~(modify-phases %standard-phases
+               (add-after 'unpack 'patch-source
+                 (lambda _
+                   ;; Don't create 'icon-theme.cache'
+                   (substitute* "meson.build"
+                     (("meson.add_install_script*") ""))))
+               (add-after 'glib-or-gtk-wrap 'wrap-pixbuf
+                 (lambda* (#:key outputs #:allow-other-keys)
+                   (let ((viewnior (string-append #$output "/bin/viewnior")))
+                     (wrap-program viewnior
+                       ;; Wrap GDK_PIXBUF_MODULE_FILE so viewnior can be used
+                       ;; to view JPG, PNG and SVG, without the user needing
+                       ;; to install gdk-pixbuf or librsvg.
+                       `("GDK_PIXBUF_MODULE_FILE" =
+                         (,(getenv "GDK_PIXBUF_MODULE_FILE"))))))))
+           #:tests? #f))                    ;no tests
     (native-inputs
      (list gettext-minimal
            `(,glib "bin")               ;glib-genmarshal
@@ -442,7 +454,10 @@ (define-public viewnior
     (inputs
      (list exiv2
            gdk-pixbuf
-           gtk+-2))
+           gtk+-2
+           ;; not needed, there is SVG support already: (librsvg-for-system)
+           ;; uncomment for webp support: webp-pixbuf-loader
+           ))
     (home-page "https://siyanpanayotov.com/project/viewnior")
     (synopsis "Simple, fast and elegant image viewer")
     (description "Viewnior is an image viewer program.  Created to be simple,

base-commit: 15a41ec5a7f0629f78ede29bd7867cd8dc22c992
-- 
2.47.1