Tuesday, November 8, 2011

Using Imagemagick shell command to crop figures

How to crop figure and save as png.
This is useful for cropping similar figures located in a folder.

Copy the code, save as cropfig.sh
and then run the cropfig.sh in your terminal...

#!/bin/bash
width=1800;
height=1680;
x_offset=502;
y_offset=40;
filelist=`ls | grep '.png'`
for image_file in $filelist
do
preextensionfilename=`convert $image_file -format "%t" info:`
convert $image_file -crop ${width}x${height}+${x_offset}+${y_offset} \
${preextensionfilename}_${width}x${height}.png
done


No comments: