Thumbnails: Difference between revisions

From NixOS Wiki
Ekosz (talk | contribs)
No edit summary
Jopejoe1 (talk | contribs)
thumbnailer is already included in package
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:


== Creating custom thumbnailers ==
== Creating custom thumbnailers ==
Most package mangers accept the [https://specifications.freedesktop.org/thumbnail-spec/thumbnail-spec-latest.html Thumbnail Managing Standard], by using it you can create your own thumbnailer for any file format, this can be done by:
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.
# First you need to figure out how to create a <code>.png</code> image from a file in the desired format.
Line 51: Line 51:


=== FFmpeg thumbnailer ===
=== FFmpeg thumbnailer ===
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> (thumbnailer entry taken from [https://raw.githubusercontent.com/dirkvdb/ffmpegthumbnailer/master/dist/ffmpegthumbnailer.thumbnailer ffmpegthumbnailer repo]):
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>:
 
<syntaxhighlight lang="nix">
<syntaxhighlight lang="nix">
# configuration.nix
# configuration.nix
{ pkgs, ... }: {
{ pkgs, ... }: {
   environment.systemPackages = [
   environment.systemPackages = [
     (
     pkgs.ffmpegthumbnailer
      pkgs.writeTextFile {
        name = "ffmpegthumbnailer.thumbnailer";
    destination = "/share/thumbnailers/ffmpegthumbnailer.thumbnailer";
    text = ''
  [Thumbnailer Entry]
          TryExec=${pkgs.ffmpegthumbnailer}/bin/ffmpegthumbnailer
          Exec=sh -c "${pkgs.ffmpegthumbnailer}/bin/ffmpegthumbnailer -i %i -o %o -s %s -f"
          MimeType=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>
</syntaxhighlight>

Latest revision as of 19:32, 4 September 2024

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;
        '';
      }
    )
  ];
}

FFmpeg thumbnailer

On minimal GNOME environments (for example ones with the option services.gnome.core-utilities.enable set to false, or ones without pkgs.gnome.totem), video thumbnails do not work by default. To fix this, you can use ffmpegthumbnailer:

# configuration.nix
{ pkgs, ... }: {
  environment.systemPackages = [
    pkgs.ffmpegthumbnailer
  ];
}