ImageMagick is a commandline application for editing images.
I find it good for cropping and scaling images in bulk, creating animated gifs and assembling sprite sheets.
You can even stick the commands in a script to run. My examples will output all results to the Home directory.
I'll also mention some tips and pitfalls I've discovered.
First some resources.
The ImageMagick site
The good intro
The bad official docs. These are detailed but also obsolete, misspelled, verbose and purple.
You can generate some builtin images to practice on
magick rose: rose.gif
convert png to gif to remove whitespace
convert dude.png +repage dude.gif
Scale
Avoid blur with -scale and a whole fraction %
Double blow up:
$ convert in.gif -scale 200% out.gif
Half shrink:
$ convert in.gif -scale 50% out.gif
To crop a sprite sheet
do this
convert bobs.gif -crop 32x32 +repage d%03d.gif
There's also a two step way of doing this. First crop the spritesheet into horizontal strips
Then swap the dimensions to vertically crop the strips.
Crop 10px from the top
$ convert in.gif -crop +0+10 +repage ftop.gif
Crop 10px from the left
$ convert in.gif -crop +10+0 +repage fleft.gif
Crop 10px from the right
$ convert in.gif -crop -10+0 +repage fright.gif
Crop 10px from the bottom
$ convert in.gif -crop +0-10 +repage fbtm.gif
In this row I want to crop just the sprites
Since I know every sprites is 32px wide
To put these 3 sprites in a row
I can target them individually
magick d009.gif d010.gif d011.gif +append tv1.gif
Or I can grab a range based on filename!
magick d%03d.gif[9-11] +append tv1.gif
To stack them up
magick d1.gif d2.gif d3.gif -append tv1.gif
For offset, the origin (0,0) is upper-left corner. (w)x(h)(+right)(+down)
The following negatively colours a (tall) area:
First in topL corner 10px to the right, 20px down. turned a red rose blue
magick rose: -region '100x200+10+20' -negate rNeg1.gif
This spills off the left edge
magick rose: -region '100x200-10+20' -negate rNeg2.gif
This resets the origin (0,0) to the centre so offset is below+L of it.
magick rose: -gravity center -region '100x200-10+20' -negate rNeg3.gif
dead centre
magick rose: -gravity center -region '100x200' -negate rNeg4.gif
source
Make a gif
magick d00%d.gif[0-7] bl.gif
Tips:
Convert a sprite to gif before cropping to see the whitespace that pngs hide.
Name output to %03d if it will generate 100s of sprites.
Output filenames start 00, 01, etc. If you want output to start on 01 use "null:" as the first input
convert null: b00.gif -crop 32x0 +repage f%02d.gif
This produces f01.gif, f02.gif