Thumbnails: Difference between revisions

Crazivik (talk | contribs)
Added subsection for 'raw' / camera image format thumbnails
m Use same MimeType
 
(16 intermediate revisions by 5 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 using window managers like sway or hyperland
* Custom environments built from ground-up using window managers like [[Sway]] or [[Hyprland]]


=== Enable Video Thumbnails ===
=== Save yourself hours of troubleshooting!! ===
To enable thumbnails for video files use <code>ffmpeg-headless</code> to decode videos and <code>fmpegthumbnailer</code> to generate thumbnails.
Thumbnailers may already be installed in your system as dependencies of image/video applications but are not activated.


Thumbnails for the following MimeTypes are enabled: ''video/jpeg; video/mp4; video/mpeg; video/quicktime; video/x-ms-asf; video/x-ms-wm; video/x-ms-wmv; video/x-ms-asx; video/x-ms-wmx; video/x-ms-wvx; video/x-msvideo; video/x-flv; video/x-matroska; application/x-matroska; application/mxf; video/3gp; video/3gpp; video/dv; video/divx; video/fli; video/flv; video/mp2t; video/mp4v-es; video/msvideo; video/ogg; video/vivo; video/vnd.avi; video/vnd.divx; video/vnd.mpegurl; video/vnd.rn-realvideo; application/vnd.rn-realmedia; video/vnd.vivo; video/webm; video/x-anim; video/x-avi; video/x-flc; video/x-fli; video/x-flic; video/x-m4v; video/x-mpeg; video/x-mpeg2; video/x-nsv; video/x-ogm+ogg; video/x-theora+ogg.''
Run <code>cd /run/current-system/sw/share/thumbnailers && ls</code> to list installed thumbnailers. If relevant .thumbnailer files are present and we still don't have thumbnails in our file explorer then we may need to activate them by updating symlinks to <code>share/thumbnailers</code>


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


   environment.systemPackages = with pkgs; [
   environment.pathsToLink = [
     ffmpeg-headless
     "share/thumbnailers"
    ffmpegthumbnailer
   ];
   ];


  # 'ffmpegthumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}
    # but thumbnails are not displayed unless symlinks to 'share/thumbnailers' are also defined
</syntaxhighlight>
 
=== Enable Video Thumbnails ===
To enable thumbnails for video files use <code>ffmpeg-headless</code> to decode videos and <code>fmpegthumbnailer</code> to generate thumbnails.
 
Thumbnails for the following MimeTypes are enabled: ''video/jpeg; video/mp4; video/mpeg; video/quicktime; video/x-ms-asf; video/x-ms-wm; video/x-ms-wmv; video/x-ms-asx; video/x-ms-wmx; video/x-ms-wvx; video/x-msvideo; video/x-flv; video/x-matroska; application/x-matroska; application/mxf; video/3gp; video/3gpp; video/dv; video/divx; video/fli; video/flv; video/mp2t; video/mp4v-es; video/msvideo; video/ogg; video/vivo; video/vnd.avi; video/vnd.divx; video/vnd.mpegurl; video/vnd.rn-realvideo; application/vnd.rn-realmedia; video/vnd.vivo; video/webm; video/x-anim; video/x-avi; video/x-flc; video/x-fli; video/x-flic; video/x-m4v; video/x-mpeg; video/x-mpeg2; video/x-nsv; video/x-ogm+ogg; video/x-theora+ogg.''


  # uncomment if this has already been defined in your configuration.nix
<syntaxhighlight lang="nix">
   environment.pathsToLink = [
# configuration.nix
     "share/thumbnailers"
{ pkgs, ... }:
 
{
   environment.systemPackages = [
     pkgs.ffmpeg-headless
    pkgs.ffmpegthumbnailer
   ];
   ];


  # 'ffmpegthumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 38: Line 48:


<syntaxhighlight lang="nix"># configuration.nix
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
  environment.systemPackages = [
    pkgs.gdk-pixbuf
  ];


   environment.systemPackages = with pkgs; [
  # 'gdk-pixbuf-thumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
     gdk-pixbuf
}</syntaxhighlight>
 
==== Thumbnails for newer image formats such as AVIF and JPEG XL ====
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)
 
    # 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>


  # 'gdk-pixbuf-thumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
=== Enable 3D Model Thumbnails ===
    # but thumbnails are not displayed unless symlinks to 'share/thumbnailers' are also defined
Thumbnails for various 3D model files can be enabled by installing f3d:<syntaxhighlight lang="nix">
# configuration.nix
{ pkgs, ... }:


  # uncomment if this has already been defined in your configuration.nix
{
   environment.pathsToLink = [
   environment.systemPackages = [  
  "share/thumbnailers"
    pkgs.f3d
   ];
   ];
}
</syntaxhighlight>


=== Enable RAW (Camera) Image Thumbnails ===
==== gdk-pixbuf thumbnailer ====
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"># configuration.nix
{ pkgs, ... }:
{
  environment.systemPackages = [
    pkgs.gdk-pixbuf
    # Allow gdk-pixbuf to thumbnail RAW photos by extracting the embedded jpeg
    (pkgs.writeTextFile {
      name = "raw-embedded-jpeg-thumbnailer";
      destination = "/share/thumbnailers/raw-embedded-jpeg.thumbnailer";
      text = ''
        [Thumbnailer Entry]
        TryExec=gdk-pixbuf-thumbnailer
        Exec=gdk-pixbuf-thumbnailer -s %s %u %o
        MimeType=image/x-canon-crw;image/x-canon-cr2;image/x-canon-cr3;image/x-adobe-dng;image/x-dng;
      '';
    })
    # Other MimeTypes that include embedded jpeg may work as well (e.g. Nikon .nef, Sony .arf, etc)
    # Test other formats by adding them above
  ];
}</syntaxhighlight>
}</syntaxhighlight>


=== Enable HEIF Image Thumbnails ===
'''exiv2-thumbnailer'''
To enable thumbnails for HEIF image format use <code>libheif</code> to decode HEIF images and <code>libheif.out</code> to generate thumbnails.


Thumbnails for the following MimeTypes are enabled: ''image/heif; image/avif.''
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, ... }:


<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


  environment.systemPackages = with pkgs; [
        tmpdir="$(mktemp -d)"
    libheif
        trap 'rm -rf "$tmpdir"' EXIT
    libheif.out
 
  ];
        exiv2 -l "$tmpdir" --extract p1 "$1"
 
        base="$(basename "$1")"
        preview="$tmpdir/\${base%.*}-preview1.jpg"
        [ ! -f "$preview" ] && preview="${preview%.*}.tif"


  # 'heif.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'  
        magick "$preview" -thumbnail "\${3}x\${3}>" -strip "png:$2"
     # but thumbnails are not displayed unless symlinks to 'share/thumbnailers' are also defined
      '';
     })


  # uncomment if this has already been defined in your configuration.nix
    (pkgs.writeTextFile {
  environment.pathsToLink = [
      name = "exiv2-thumbnailer.thumbnailer";
  "share/thumbnailers"
      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>


=== Enable RAW (Camera) Image Thumbnails ===
</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 ====
{{Warning|nufraw has not been updated since March 2nd, 2020, and may be insecure.}}
To enable thumbnails for camera RAW format use <code>nufraw</code> to decode RAW images and <code>nufraw-thumbnailer</code> to generate thumbnails.
To enable thumbnails for camera RAW format use <code>nufraw</code> to decode RAW images and <code>nufraw-thumbnailer</code> to generate thumbnails.


Line 89: Line 170:


<syntaxhighlight lang="nix"># configuration.nix
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
 
   environment.systemPackages = [  
   environment.systemPackages = with pkgs; [  
     pkgs.nufraw
     nufraw
     pkgs.nufraw-thumbnailer
     nufraw-thumbnailer
   ];
   ];


   # 'nufraw.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'  
   # 'nufraw.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'  
    # but thumbnails are not displayed unless symlinks to 'share/thumbnailers' are also defined
  # uncomment if this has already been defined in your configuration.nix
  environment.pathsToLink = [
  "share/thumbnailers"
  ];
}</syntaxhighlight>
}</syntaxhighlight>


By default nufraw-thumbnailer   
nufraw-thumbnailer   


* creates thumbnails using the embedded 'jpeg' in the camera raw files. ( <code>--noexif</code> )
* creates thumbnails using the embedded 'jpeg' in the camera raw files. ( <code>--noexif</code> )
Line 113: Line 187:


Output of <code>cat /run/current-system/sw/share/thumbnailers/nufraw.thumbnailer</code>:
Output of <code>cat /run/current-system/sw/share/thumbnailers/nufraw.thumbnailer</code>:
<syntaxhighlight lang="nix">
 
<syntaxhighlight lang="desktop">
[Thumbnailer Entry]
[Thumbnailer Entry]
TryExec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch
TryExec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch
Line 124: Line 199:
Eg: Generate thumbnails from 'raw' data (not 'embedded jpeg') + respect EXIF (eg: rotation) metadata + add support for additional camera formats
Eg: Generate thumbnails from 'raw' data (not 'embedded jpeg') + respect EXIF (eg: rotation) metadata + add support for additional camera formats


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


{
{
   environment.systemPackages = [
   environment.systemPackages = [
     nufraw
     pkgs.nufraw
     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
     (writeTextDir "share/thumbnailers/my-custom-nufraw.thumbnailer" ''
     (pkgs.writeTextFile {
      [Thumbnailer Entry]
      name = "my-custom-nufraw-thumbnailer";
      TryExec=nufraw-batch
      destination = "/share/thumbnailers/my-custom-nufraw.thumbnailer";
      Exec=nufraw-batch --silent --size %s --out-type=png --output=%o %i
      text = ''
      MimeType=image/x-adobe-dng;image/x-dng;
        [Thumbnailer Entry]
    '';)
        TryExec=nufraw-batch
        Exec=nufraw-batch --silent --size %s --out-type=png --output=%o %i
        MimeType=image/x-adobe-dng;image/x-dng;
      '';
    })
     # 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>
  # uncomment if this has already been defined in your configuration.nix
  environment.pathsToLink = [
  "share/thumbnailers"
  ];
 
}
</syntaxhighlight>
 
==== gdk-pixbuf thumbnailer ====
The gdk-pixbuf thumbnailer can also generate thumbnails (from the 'embedded jpeg') for RAW camera image formats. It cannot decode the 'raw' image data but can read the 'embedded jpeg'.
 
<syntaxhighlight lang="nix">
# configuration.nix
{ pkgs, ... }:
 
{
 
  environment.systemPackages = [
    gdk-pixbuf
    (writeTextDir "share/thumbnailers/my-custom-nufraw.thumbnailer" ''
      [Thumbnailer Entry]
      TryExec=gdk-pixbuf-thumbnailer
      Exec=gdk-pixbuf-thumbnailer -s %s %u %o
      MimeType=image/x-adobe-dng;image/x-dng;image/x-canon-cr2;image/x-canon-crw;image/x-cr2;image/x-crw;
    '';)
  ];
 
  # uncomment if this has already been defined in your configuration.nix
  environment.pathsToLink = [
  "share/thumbnailers"
  ];
 
}
</syntaxhighlight>


== '''Creating Custom Thumbnailers''' ==
== '''Creating Custom Thumbnailers''' ==
Line 207: Line 250:


<syntaxhighlight lang="nix"># configuration.nix
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }: {
{ pkgs, ... }:
 
{
   environment.systemPackages = [
   environment.systemPackages = [
     (
     (pkgs.writeTextFile {
      pkgs.writeTextFile {
      # This can be anything, it's just the name of the derivation in the nix store
        # This can be anything, it's just the name of the derivation in the nix store
      name = "krita-thumbnailer";
        name = "krita-thumbnailer";
      # This is the important part, the path under which this will be installed
        # This is the important part, the path under which this will be installed
      destination = "/share/thumbnailers/kra.thumbnailer";
        destination = "/share/thumbnailers/kra.thumbnailer";
      # The contents of your thumbnailer, don't forget to specify the full path to executables
        # The contents of your thumbnailer, don't forget to specify the full path to executables
      text = ''
        text = ''
        [Thumbnailer Entry]
          [Thumbnailer Entry]
        Exec=sh -c "${pkgs.unzip}/bin/unzip -p %i preview.png > %o"
          Exec=sh -c "${pkgs.unzip}/bin/unzip -p %i preview.png > %o"
        MimeType=application/x-krita;
          MimeType=application/x-krita;
      '';
        '';
    })
      }
    )
   ];
   ];
}</syntaxhighlight>
}</syntaxhighlight>