Jump to content

Thumbnails: Difference between revisions

From Official NixOS Wiki
Crazivik (talk | contribs)
No edit summary
f3d can create thumbnails for 3D model files
 
(16 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{expansion|Explain how thumbnails can be configured in different file managers, preferably by linking to their articles}}
{{expansion|Explain how thumbnails can be configured in different file managers, preferably by linking to their articles}}


== Creating custom thumbnailers ==
== '''Enabling Thumbnailers''' ==
Most package mangers accept the [https://specifications.freedesktop.org/thumbnail-spec/latest/index.html Thumbnail Managing Standard], by using it you can create your own thumbnailer for any file format, this can be done by:
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>
* Custom environments built from ground-up using window managers like [[Sway]] or [[Hyprland]]


# First you need to figure out how to create a <code>.png</code> image from a file in the desired format.
=== Save yourself hours of troubleshooting!! ===
# Create a <code>.thumbnailer</code> file in <code>$XDG_DATA_DIRS/thumbnailers</code>.
Thumbnailers may already be installed in your system as dependencies of image/video applications but are not activated.
# Restart your thumbnailer service (This is specific to each file manager) and test if it's working.


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


You could create a thumbnailer for [[Krita]]'s <code>.kra</code> file format like so:
<syntaxhighlight lang="nix">
# configuration.nix
{


<code>.kra</code> are zip files, with a preview stored at <code>/preview.png</code>, we can use unzip to extract the preview:
  environment.pathsToLink = [
<syntaxhighlight lang="shell">
    "share/thumbnailers"
unzip -p robot-squirrel.kra preview.png > robot-squirrel.png
  ];
</syntaxhighlight>Create a <code>.thumbnailer</code> file in any <code>$XDG_DATA_DIRS/thumbnailers</code> directory.


<syntaxhighlight lang="desktop">
}
# $HOME/.local/share/thumbnailers/kra.thumbnailer
[Thumbnailer Entry]
Exec=sh -c "unzip -p %i preview.png > %o"
MimeType=application/x-krita;
</syntaxhighlight>
</syntaxhighlight>


Restart your thumbnailer service (This is specific to each file manager) and test if it's working.
=== Enable Video Thumbnails ===
To enable thumbnails for video files use <code>ffmpeg-headless</code> to decode videos and <code>fmpegthumbnailer</code> to generate thumbnails.


After you have a working definition, you can make it reproducible like so:
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.''


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


=== FFmpeg thumbnailer ===
=== Enable Image Thumbnails ===
On minimal GNOME environments (for example ones with the option <code>services.gnome.core-utilities.enable</code> set to <code>false</code>, or ones without <code>pkgs.gnome.totem</code>), video thumbnails do not work by default. To fix this, you can use <code>ffmpegthumbnailer</code>:
To enable thumbnails for image files use <code>gdk-pixbuf</code> to decode images and generate thumbnails.
 
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, ... }:
 
{
{
  environment.systemPackages = [
    pkgs.gdk-pixbuf
  ];


   # Install ffmpegthumbnailer package
   # 'gdk-pixbuf-thumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
   environment.systemPackages = [
}</syntaxhighlight>
     pkgs.ffmpegthumbnailer
 
=== Enable 3D Model Thumbnails ===
Thumbnails for various 3D model files can be enabled by installing f3d:<syntaxhighlight lang="nix">
# configuration.nix
{ pkgs, ... }:
 
{
   environment.systemPackages = [  
     pkgs.f3d
   ];
   ];
}
</syntaxhighlight>
=== Enable HEIF Image Thumbnails ===
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.''
<syntaxhighlight lang="nix">
# configuration.nix
{ pkgs, ... }:


  # Installing above package automatically creates the ffmpegthumbnailer.thumbnailer
{
    # in '/run/current-system/sw/share/thumbnailers' but thumbnails are not displayed
   environment.systemPackages = [  
    # until symlinks to 'share/thumbnailers' are defined
     pkgs.libheif
   environment.pathsToLink = [
    pkgs.libheif.out
     "share/thumbnailers"
   ];
   ];


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


=== HEIC thumbnailer ===
=== Enable RAW (Camera) Image Thumbnails ===
On minimal GNOME environments as explained in the FFmpeg thumbnailer section above HEIC thumbnails do not work despite the <code>libheif</code> package being installed. To fix this, you can use the following:
 
==== 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">
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }:  
{ 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>


   environment.systemPackages = with pkgs; [  
==== nufraw-thumbnailer ====
     libheif
{{Warning|nufraw has not been updated since March 2nd, 2020, and may be insecure.}}
     libheif.out
To enable thumbnails for camera RAW format use <code>nufraw</code> to decode RAW images and <code>nufraw-thumbnailer</code> to generate thumbnails.
 
Thumbnails for the following MimeTypes are enabled: ''image/x-canon-cr2;image/x-canon-crw;image/x-minolta-mrw;image/x-nikon-nef;image/x-pentax-pef;image/x-panasonic-rw2;image/x-panasonic-raw2;image/x-samsung-srw;image/x-olympus-orf;image/x-sony-arw.''
 
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:
 
{
   environment.systemPackages = [  
     pkgs.nufraw
     pkgs.nufraw-thumbnailer
   ];
   ];


   environment.pathsToLink = [
  # 'nufraw.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
  "share/thumbnailers"
}</syntaxhighlight>
 
nufraw-thumbnailer 
 
* creates thumbnails using the embedded 'jpeg' in the camera raw files. ( <code>--noexif</code> )
* does not respect the EXIF metadata. ( <code>--embedded-image</code> )
 
Output of <code>cat /run/current-system/sw/share/thumbnailers/nufraw.thumbnailer</code>:
 
<syntaxhighlight lang="desktop">
[Thumbnailer Entry]
TryExec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch
Exec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch --silent --size %s --out-type=png --noexif --output=%o --embedded-image %i
MimeType=image/x-canon-cr2;image/x-canon-crw;image/x-minolta-mrw;image/x-nikon-nef;image/x-pentax-pef;image/x-panasonic-rw2;image/x-panasonic-raw2;image/x-samsung-srw;image/x-olympus-orf;image/x-sony-arw
</syntaxhighlight>
 
Additional cameras<ref>https://github.com/killhellokitty/nufraw-thumbnailer</ref> beyond those listed in the stock <code>nufraw.thumbnailer</code> file are also supported. The following additional MimeTypes are supported: ''image/x-adobe-dng; image/x-dcraw; image/x-fuji-raf; image/x-kodak-dcr; image/x-kodak-k25; image/x-kodak-kdc; image/x-nikon-nrw; image/x-panasonic-raw; image/x-sigma-x3f; image/x-sony-srf; image/x-sony-sr2''
 
Eg: Generate thumbnails from 'raw' data (not 'embedded jpeg') + respect EXIF (eg: rotation) metadata + add support for additional camera formats
 
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:
 
{
   environment.systemPackages = [
    pkgs.nufraw
    pkgs.nufraw-thumbnailer
    # Thumbnails from 'raw' data and include EXIF tags for Adobe-DNG images
    (pkgs.writeTextFile {
      name = "my-custom-nufraw-thumbnailer";
      destination = "/share/thumbnailers/my-custom-nufraw.thumbnailer";
      text = ''
        [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
    # thumbnails generated from the 'embedded jpeg' without the EXIF metadata
   ];
   ];
}</syntaxhighlight>
== '''Creating Custom Thumbnailers''' ==
Most package mangers accept the [https://specifications.freedesktop.org/thumbnail-spec/latest/index.html Thumbnail Managing Standard], by using it you can create your own thumbnailer for any file format, this can be done by:


}
# First you need to figure out how to create a <code>.png</code> image from a file in the desired format.
# Create a <code>.thumbnailer</code> file in <code>$XDG_DATA_DIRS/thumbnailers</code>.
# Restart your thumbnailer service (This is specific to each file manager) and test if it's working.
 
=== Example ===
 
You could create a thumbnailer for [[Krita]]'s <code>.kra</code> file format like so:
 
<code>.kra</code> are zip files, with a preview stored at <code>/preview.png</code>, we can use unzip to extract the preview:
<syntaxhighlight lang="shell">
unzip -p robot-squirrel.kra preview.png > robot-squirrel.png
</syntaxhighlight>Create a <code>.thumbnailer</code> file in any <code>$XDG_DATA_DIRS/thumbnailers</code> directory.
 
<syntaxhighlight lang="desktop">
# $HOME/.local/share/thumbnailers/kra.thumbnailer
[Thumbnailer Entry]
Exec=sh -c "unzip -p %i preview.png > %o"
MimeType=application/x-krita;
</syntaxhighlight>
</syntaxhighlight>
Restart your thumbnailer service (This is specific to each file manager) and test if it's working.
After you have a working definition, you can make it reproducible like so:
<syntaxhighlight lang="nix"># configuration.nix
{ pkgs, ... }:
{
  environment.systemPackages = [
    (pkgs.writeTextFile {
      # This can be anything, it's just the name of the derivation in the nix store
      name = "krita-thumbnailer";
      # This is the important part, the path under which this will be installed
      destination = "/share/thumbnailers/kra.thumbnailer";
      # The contents of your thumbnailer, don't forget to specify the full path to executables
      text = ''
        [Thumbnailer Entry]
        Exec=sh -c "${pkgs.unzip}/bin/unzip -p %i preview.png > %o"
        MimeType=application/x-krita;
      '';
    })
  ];
}</syntaxhighlight>

Latest revision as of 17:30, 14 December 2025

☶︎
This article or section needs to be expanded. Further information may be found in the related discussion page. Please consult the pedia article metapage for guidelines on contributing.

Enabling Thumbnailers

On minimal / custom desktop environments thumbnails in file explorers may not work by default. For example:

  • GNOME environments with the option services.gnome.core-utilities.enable = false;
  • Custom environments built from ground-up using window managers like Sway or Hyprland

Save yourself hours of troubleshooting!!

Thumbnailers may already be installed in your system as dependencies of image/video applications but are not activated.

Run cd /run/current-system/sw/share/thumbnailers && ls 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 share/thumbnailers

# configuration.nix
{

  environment.pathsToLink = [
    "share/thumbnailers"
  ];

}

Enable Video Thumbnails

To enable thumbnails for video files use ffmpeg-headless to decode videos and fmpegthumbnailer 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.

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [
    pkgs.ffmpeg-headless
    pkgs.ffmpegthumbnailer
  ];

  # 'ffmpegthumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}

Enable Image Thumbnails

To enable thumbnails for image files use gdk-pixbuf to decode images and generate thumbnails.

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.

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [ 
    pkgs.gdk-pixbuf
  ];

  # 'gdk-pixbuf-thumbnailer.thumbnailer' is created in '/run/current-system/sw/share/thumbnailers'
}

Enable 3D Model Thumbnails

Thumbnails for various 3D model files can be enabled by installing f3d:

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [ 
    pkgs.f3d
  ];
}

Enable HEIF Image Thumbnails

To enable thumbnails for HEIF image format use libheif to decode HEIF images and libheif.out to generate thumbnails.

Thumbnails for the following MimeTypes are enabled: image/heif; image/avif.

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [ 
    pkgs.libheif
    pkgs.libheif.out
  ];

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

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.

# 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
  ];
}

nufraw-thumbnailer

⚠︎
Warning: nufraw has not been updated since March 2nd, 2020, and may be insecure.

To enable thumbnails for camera RAW format use nufraw to decode RAW images and nufraw-thumbnailer to generate thumbnails.

Thumbnails for the following MimeTypes are enabled: image/x-canon-cr2;image/x-canon-crw;image/x-minolta-mrw;image/x-nikon-nef;image/x-pentax-pef;image/x-panasonic-rw2;image/x-panasonic-raw2;image/x-samsung-srw;image/x-olympus-orf;image/x-sony-arw.

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [ 
    pkgs.nufraw
    pkgs.nufraw-thumbnailer
  ];

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

nufraw-thumbnailer

  • creates thumbnails using the embedded 'jpeg' in the camera raw files. ( --noexif )
  • does not respect the EXIF metadata. ( --embedded-image )

Output of cat /run/current-system/sw/share/thumbnailers/nufraw.thumbnailer:

[Thumbnailer Entry]
TryExec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch
Exec=/nix/store/piss9dl8i5xnfm5yagdffgxycm8lsqpl-nufraw-0.43-3/bin/nufraw-batch --silent --size %s --out-type=png --noexif --output=%o --embedded-image %i
MimeType=image/x-canon-cr2;image/x-canon-crw;image/x-minolta-mrw;image/x-nikon-nef;image/x-pentax-pef;image/x-panasonic-rw2;image/x-panasonic-raw2;image/x-samsung-srw;image/x-olympus-orf;image/x-sony-arw

Additional cameras[1] beyond those listed in the stock nufraw.thumbnailer file are also supported. The following additional MimeTypes are supported: image/x-adobe-dng; image/x-dcraw; image/x-fuji-raf; image/x-kodak-dcr; image/x-kodak-k25; image/x-kodak-kdc; image/x-nikon-nrw; image/x-panasonic-raw; image/x-sigma-x3f; image/x-sony-srf; image/x-sony-sr2

Eg: Generate thumbnails from 'raw' data (not 'embedded jpeg') + respect EXIF (eg: rotation) metadata + add support for additional camera formats

# configuration.nix
{ pkgs, ... }:

{
  environment.systemPackages = [
    pkgs.nufraw
    pkgs.nufraw-thumbnailer
    # Thumbnails from 'raw' data and include EXIF tags for Adobe-DNG images
    (pkgs.writeTextFile {
      name = "my-custom-nufraw-thumbnailer";
      destination = "/share/thumbnailers/my-custom-nufraw.thumbnailer";
      text = ''
        [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
    # thumbnails generated from the 'embedded jpeg' without the EXIF metadata
  ];
}

Creating Custom Thumbnailers

Most package mangers accept the Thumbnail Managing Standard, by using it you can create your own thumbnailer for any file format, this can be done by:

  1. First you need to figure out how to create a .png image from a file in the desired format.
  2. Create a .thumbnailer file in $XDG_DATA_DIRS/thumbnailers.
  3. Restart your thumbnailer service (This is specific to each file manager) and test if it's working.

Example

You could create a thumbnailer for Krita's .kra file format like so:

.kra are zip files, with a preview stored at /preview.png, we can use unzip to extract the preview:

unzip -p robot-squirrel.kra preview.png > robot-squirrel.png

Create a .thumbnailer file in any $XDG_DATA_DIRS/thumbnailers directory.

# $HOME/.local/share/thumbnailers/kra.thumbnailer
[Thumbnailer Entry]
Exec=sh -c "unzip -p %i preview.png > %o"
MimeType=application/x-krita;

Restart your thumbnailer service (This is specific to each file manager) and test if it's working.

After you have a working definition, you can make it reproducible like so:

# configuration.nix
{ pkgs, ... }:

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