Skip to content

Instantly share code, notes, and snippets.

@metaphore
Last active January 1, 2023 15:59
Show Gist options
  • Save metaphore/9a2ac696854628470b6a0cba5549e7b0 to your computer and use it in GitHub Desktop.
Save metaphore/9a2ac696854628470b6a0cba5549e7b0 to your computer and use it in GitHub Desktop.
Gnome | Aseprite thumbnail generator
#!/usr/bin/sh
if [ $# -ge 2 -a $# -lt 4 ]; then
mkdir -p /tmp/Aseprite
filename="$(mktemp -d -p /tmp/Aseprite/).png"
if [ $# -eq 2 ]; then
aseprite -b --frame-range "0,0" $1 --trim --sheet $filename
elif [ $# -eq 3 ]; then
aseprite -b --frame-range "0,0" $1 --shrink-to "$3,$3" --trim --sheet $filename
fi
test="/home/metaphore/Desktop/tmp-icon/output.png"
mkdir -p $(dirname "$2"); mv $filename $2;
convert -colorspace sRGB $2 -background transparent -flatten -filter Point -thumbnail $3x$3 -gravity center -extent $3x$3 png32:$2
else
echo "Parameters for aseprite thumbnailer are: inputfile outputfile [size]"
fi
[Thumbnailer Entry]
TryExec=aseprite-thumbnailer
Exec=aseprite-thumbnailer %i %o %s
MimeType=image/x-aseprite
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="image/x-aseprite">
<comment xml:lang="en">Aseprite Pixel Art</comment>
<magic priority="50">
<match type="little16" value="0xA5E0" offset="4"/>
</magic>
<glob pattern="*.ase"/>
<glob pattern="*.aseprite"/>
<icon name="aseprite"/>
</mime-type>
</mime-info>
@metaphore
Copy link
Author

metaphore commented Jan 1, 2023

Pre-requirements:

  1. Aseprite must be installed and aseprite executable should be available from the PATH.
  2. Imagemagic must be installed and convert should be available from the PATH.

Installation:

  1. Register a new mime type: update-mime-database aseprite.xml.
  2. Place aseprite-thumbnailer to /usr/bin/aseprite-thumbnailer (don't forget to make it executable).
  3. Place aseprite.thumbnailer to ~/.local/share/thumbnailers/aseprite.thumbnailer
  4. Delete all failed thumbs: rm -r ~/.cache/thumbnails/failed

P.S. Tested with Pop!_OS Gnome 42

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment