Saturday 12 November 2011

Image slicing and dicing

Handy code to chop up an image file:
Takes a file called convert_cake_layers.png
Chops it up by the sizes 300 X 154 and outputs the files cl_0.png -> cl_9.png


#!/bin/bash
seq 0 9 | awk "{ print \"convert cake_layers.png -crop 300x154+0+\" \$0*154 \" cl_\" \$0 \".png\" }" | bash

1 comment:

  1. You can do this a bit cleaner (eg. not generating code) in POSIX-compatible shell:

    for X in $(seq 0 9); do convert cake_layers.png -crop 300x154+0+$(($X * 154)) cl_${X}.png; don

    ReplyDelete