--- title: rename and resize commands subtitle: making mtg card thumbnails author: david marsh date: 2023-11-09 keywords: [image magic, convert, mtg, magic the gathering] img: mtg-atq-60.webp alt: An Magic The Gathering card abstract: Here's a few commands I used to make thumbnails for my mtg cards. --- For my [mtg page](list_of_mtg.html), 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](mtg-atq-60.webp) First of all, I grab an image from [scryfall.com](https://scryfall.com). There are two issues I need to solve: ### change the file name 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](http://plasmasturm.org/code/rename/) command (installed via the [homebrew formula](https://formulae.brew.sh/formula/rename)): *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' ``` ### change the image size 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 ```