making mtg card thumbnails
2023-11-09
For my mtg page, I wanted to add small thumbnails so I could see at a quick glance which card I was refering too, and also to make the page a bit more pretty.
mtg card
First of all, I grab an image from scryfall.com. There are two issues I need to solve:
The files are named set-99-name.png
, and I want them to be just mtg-set-99.png
. Having the card name as part of the image filename isn’t needed and just makes dealing with the text harder as the line length changes a lot. Adding the mtg-
part makes tracking these files much simpler in the large source dir I use to build this website.
Using the rename command (installed via the homebrew formula):
Note: the -n flag is a dry run
rename -n 's/^([a-z]{3}-[0-9]{1,3}).*\.png/mtg-$1.png/' *.png
This saves the part I’m interested in and want to keep using the brackets and throws away the rest. The file has mtg-
prepended, and the saved part added using $1
. Lastly it appends .png
to the filename.
For example:
$ rename -n 's/^([a-z]{3}-[0-9]{1,3}).*\.png/mtg-$1.png/' *.png
'hml-20-truce.png' would be renamed to 'mtg-hml-20.png'
'hml-22-baki-s-curse.png' would be renamed to 'mtg-hml-22.png'
'hml-41-baron-sengir.png' would be renamed to 'mtg-hml-41.png'
This is simple and something I do a lot. As I only want a very small thumbnail, 75x100 or so is good enough. I use this command to loop over the files once they’ve been renamed:
for i in mtg-*.png ; do convert $i -trim -resize 75x105\> $i ; done