Thumbnails: Difference between revisions

Joshbuker (talk | contribs)
Update RAW thumbnail recommendations and use `pkgs.` instead of `with pkgs;`
f3d can create thumbnails for 3D model files
 
(6 intermediate revisions by one other user 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 hyperland
* Custom environments built from ground-up using window managers like [[Sway]] or [[Hyprland]]


=== Save yourself hours of troubleshooting!! ===
=== Save yourself hours of troubleshooting!! ===
Line 30: Line 30:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
   environment.systemPackages = [
   environment.systemPackages = [
     pkgs.ffmpeg-headless
     pkgs.ffmpeg-headless
Line 39: Line 39:


   # 'ffmpegthumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
   # 'ffmpegthumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}
}
</syntaxhighlight>
</syntaxhighlight>
Line 50: Line 49:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
   environment.systemPackages = [  
   environment.systemPackages = [  
     pkgs.gdk-pixbuf
     pkgs.gdk-pixbuf
Line 58: Line 57:


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


}</syntaxhighlight>
{
  environment.systemPackages = [
    pkgs.f3d
  ];
}
</syntaxhighlight>


=== Enable HEIF Image Thumbnails ===
=== Enable HEIF Image Thumbnails ===
Line 68: Line 78:
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
   environment.systemPackages = [  
   environment.systemPackages = [  
     pkgs.libheif
     pkgs.libheif
Line 77: Line 87:


   # 'heif.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
   # 'heif.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}
}
</syntaxhighlight>
</syntaxhighlight>


=== Enable RAW (Camera) Image Thumbnails ===
=== 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>


==== nufraw-thumbnailer ====
==== nufraw-thumbnailer ====
Line 90: Line 126:


<syntaxhighlight lang="nix"># configuration.nix
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:  
{ pkgs, ... }:
 
{
{
   environment.systemPackages = [  
   environment.systemPackages = [  
     pkgs.nufraw
     pkgs.nufraw
Line 99: Line 135:


   # 'nufraw.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'  
   # 'nufraw.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'  
}</syntaxhighlight>
}</syntaxhighlight>


Line 109: Line 144:
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 159:


{
{
   environment.systemPackages = [
   environment.systemPackages = [
     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 140: Line 174:
     })
     })
     # 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>
==== gdk-pixbuf thumbnailer ====
The gdk-pixbuf thumbnailer can also generate thumbnails (from 'embedded jpeg') for RAW camera image formats. It cannot decode 'raw' image data but can read the 'embedded jpeg'.
<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>


== '''Creating Custom Thumbnailers''' ==
== '''Creating Custom Thumbnailers''' ==
Line 202: Line 206:


<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>