naelstrof/maim

How to get height and width of the image into the filename

YarekTyshchenko opened this issue · 2 comments

I like that maim follows unix philosophy of doing one thing, so file naming may not belong in the code, but to replace scrot I would like to generate filenames such as: 2022-01-26-175949_175x176_scrot.png (So date and Height x Width of the image)

I'd be happy with an update to the readme that could use an external program to get the width and height too.

FYI: Switching because of the white line selection bug :D

foxpy commented

Well, first of all, if you use maim -s, then you could split it into some bash script which calls slop first (it outputs coordinates in WxH+X+Y format) and then calls maim (maim -g "$slop_output") saving result with appropriate file name.

If you don't use maim -s, then you probably want to save image and then rename it. I have quickly came up with s simple snippet to do this using ffprobe and grep:

$ ffprobe -hide_banner input.png 2>&1 | grep -Po '([0-9]+x[0-9]+)'
1366x768
$

Thanks for the tip. Here's a finished script

#!/bin/bash
# Maim scrot -s replacement

set -euo pipefail

date=$(date +%F-%H%M%S)
capture=$(mktemp -t maim_$date.XXXXX)

echo "Capturing into $capture"
maim -s -u > $capture

dim=$(ffprobe -hide_banner $capture 2>&1 | grep -Po '([0-9]+x[0-9]+)')
echo "Dimensions: $dim"

mv -v $capture ~/${date}_${dim}_scrot.png