index all rss mastodon twitter github linkedin email
Álvaro Ramírez

Álvaro Ramírez

06 October 2023 Trimming video screenshots

A quick one… I recently wanted to trim the black borders around a video screenshot. While I could use an image editor to manually select and trim, I wondered if there was an imagemagick trick somewhere out there for such a thing… and of course there was:

magick convert -fuzz 3% -define trim:percent-background=0% -trim +repage path/to/input.png path/to/output.png

Pretty neat. It does the job, but I won't remember it next time. May as well make another dwim-shell-command function out of it and conveniently invoke from Emacs via a memorable name plus fuzzy search.


(defun dwim-shell-commands-image-trim-borders ()
  "Trim image(s) border (useful for video screenshots)."
   "Trim image border"
   "magick convert -fuzz 3% -define trim:percent-background=0% -trim +repage '<<f>>' '<<fne>>_trimmed.<<e>>'"
   :utils "magick"))

While the screenshot I've just used was a little blurry, it's from the movie Tron Legacy, and it features Emacs eshell. This is old news, though well covered.


dwim-shell-commands-image-trim-borders is now added to dwim-shell-commands.el