Thumbnails: Difference between revisions

Joshbuker (talk | contribs)
m Fix typos and whitespace consistency
m Use same MimeType
 
(9 intermediate revisions by 4 users not shown)
Line 4: Line 4:
On minimal / custom desktop environments thumbnails in file explorers may not work by default. For example:
On minimal / custom desktop environments thumbnails in file explorers may not work by default. For example:


* GNOME environments with the option <code>services.gnome.core-utilities.enable = false;</code>
* [[GNOME]] environments with the option <code>services.gnome.core-utilities.enable = false;</code>
* Custom environments built from ground-up using window managers like sway or hyprland
* Custom environments built from ground-up using window managers like [[Sway]] or [[Hyprland]]


=== Save yourself hours of troubleshooting!! ===
=== Save yourself hours of troubleshooting!! ===
Line 47: Line 47:
Thumbnails for the following MimeTypes are enabled: ''image/png; image/jpeg; image/bmp; image/x-bmp; image/x-MS-bmp; image/gif; image/x-icon; image/x-ico; image/x-win-bitmap; image/vnd.microsoft.icon; application/ico; image/ico; image/icon; text/ico; image/x-portable-anymap; image/x-portable-bitmap; image/x-portable-graymap; image/x-portable-pixmap; image/tiff; image/x-xpixmap; image/x-xbitmap; image/x-tga; image/x-icns; image/x-quicktime; image/qtif.''
Thumbnails for the following MimeTypes are enabled: ''image/png; image/jpeg; image/bmp; image/x-bmp; image/x-MS-bmp; image/gif; image/x-icon; image/x-ico; image/x-win-bitmap; image/vnd.microsoft.icon; application/ico; image/ico; image/icon; text/ico; image/x-portable-anymap; image/x-portable-bitmap; image/x-portable-graymap; image/x-portable-pixmap; image/tiff; image/x-xpixmap; image/x-xbitmap; image/x-tga; image/x-icns; image/x-quicktime; image/qtif.''


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix"># configuration.nix
# configuration.nix
{ pkgs, ... }:
{ pkgs, ... }:


Line 59: Line 58:
}</syntaxhighlight>
}</syntaxhighlight>


=== Enable HEIF Image Thumbnails ===
==== Thumbnails for newer image formats such as AVIF and JPEG XL ====
To enable thumbnails for HEIF image format use <code>libheif</code> to decode HEIF images and <code>libheif.out</code> to generate thumbnails.
For newer image formats not included in <code>gdk-pixbuf</code> you can enable thumbnails by adding their specific image libraries into the system packages as seen below<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:
 
{
  environment.systemPackages = [
    # For general HEIF container support (this includes the AVIF file format)
    pkgs.libheif.bin # provides heif-thumbnailer (the program that generates HEIF thumbnails)
    pkgs.libheif.out # provides heif.thumbnailer (allows for the viewing of HEIF thumbnails)


Thumbnails for the following MimeTypes are enabled: ''image/heif; image/avif.''
    # For more newer AVIF specific support usually not needed if libheif is installed
    pkgs.libavif
   
    # For JXL(JPEG XL) support
    pkgs.libjxl
   
    # For WebP support
    pkgs.webp-pixbuf-loader
  ];
  # All of the thumbnailers are created in '/run/current-system/sw/share/thumbnailers'
}</syntaxhighlight>


<syntaxhighlight lang="nix">
=== Enable 3D Model Thumbnails ===
Thumbnails for various 3D model files can be enabled by installing f3d:<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }:
{ pkgs, ... }:
Line 70: Line 87:
{
{
   environment.systemPackages = [  
   environment.systemPackages = [  
     pkgs.libheif
     pkgs.f3d
    pkgs.libheif.out
   ];
   ];
  # 'heif.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 83: Line 97:
gdk-pixbuf can be used to generate thumbnails for RAW camera image formats by reading the embedded jpeg. This embedded jpeg is typically generated in the camera or overwritten by your RAW editing software, and may not match what the photo looks like when opened in a viewer or editor.
gdk-pixbuf can be used to generate thumbnails for RAW camera image formats by reading the embedded jpeg. This embedded jpeg is typically generated in the camera or overwritten by your RAW editing software, and may not match what the photo looks like when opened in a viewer or editor.


<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix"># configuration.nix
# configuration.nix
{ pkgs, ... }:
{ pkgs, ... }:


Line 103: Line 116:
     # Other MimeTypes that include embedded jpeg may work as well (e.g. Nikon .nef, Sony .arf, etc)
     # Other MimeTypes that include embedded jpeg may work as well (e.g. Nikon .nef, Sony .arf, etc)
     # Test other formats by adding them above
     # Test other formats by adding them above
  ];
}</syntaxhighlight>
'''exiv2-thumbnailer'''
exiv2 can as well generate thumbnails for RAW camera formats by extracting their embedded JPEG or TIFF previews, making thumbnail creation fast without full RAW decoding. It may also support a wider range of RAW formats than gdk‑pixbuf, since it works directly with metadata rather than relying on codec‑level image loaders.<syntaxhighlight lang="nix">
# configuration.nix
{ pkgs, ... }:
{
  environment.systemPackages = [
    # exiv2-based RAW thumbnailer (extracts embedded JPEG/TIFF)
    (pkgs.writeShellApplication {
      name = "exiv2-thumbnailer";
      runtimeInputs = [ pkgs.exiv2 pkgs.imagemagick ];
      text = ''
        #!${pkgs.bash}/bin/bash
        set -euo pipefail
        tmpdir="$(mktemp -d)"
        trap 'rm -rf "$tmpdir"' EXIT
        exiv2 -l "$tmpdir" --extract p1 "$1"
        base="$(basename "$1")"
        preview="$tmpdir/\${base%.*}-preview1.jpg"
        [ ! -f "$preview" ] && preview="${preview%.*}.tif"
        magick "$preview" -thumbnail "\${3}x\${3}>" -strip "png:$2"
      '';
    })
    (pkgs.writeTextFile {
      name = "exiv2-thumbnailer.thumbnailer";
      destination = "/share/thumbnailers/exiv2-thumbnailer.thumbnailer";
      text = ''
        [Thumbnailer Entry]
        TryExec=exiv2-thumbnailer
        Exec=exiv2-thumbnailer %i %o
        MimeType=image/x-canon-crw;image/x-canon-cr2;image/x-canon-cr3;image/x-adobe-dng;image/x-dng;
      '';
    })
   ];
   ];
}
}
</syntaxhighlight>
 
</syntaxhighlight>For a more complete solution, see the NixOS port of [https://github.com/stackcoder/nixos-nautilus-raw-thumbnails nautilus‑raw‑thumbnails].


==== nufraw-thumbnailer ====
==== nufraw-thumbnailer ====
Line 150: Line 206:
     pkgs.nufraw
     pkgs.nufraw
     pkgs.nufraw-thumbnailer
     pkgs.nufraw-thumbnailer
     # Thumbnails form 'raw' data and include EXIF tags for Adobe-DNG images
     # Thumbnails from 'raw' data and include EXIF tags for Adobe-DNG images
     (pkgs.writeTextFile {
     (pkgs.writeTextFile {
       name = "my-custom-nufraw-thumbnailer";
       name = "my-custom-nufraw-thumbnailer";
Line 162: Line 218:
     })
     })
     # MimeTypes not listed here but listed in the default nufraw.thumbnailer will continue displaying
     # MimeTypes not listed here but listed in the default nufraw.thumbnailer will continue displaying
      # thumbnails generated form the 'embedded jpeg' without the EXIF metadata
    # thumbnails generated from the 'embedded jpeg' without the EXIF metadata
   ];
   ];
}</syntaxhighlight>
}</syntaxhighlight>