Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have several hundred images that I need to crop and save as PNG without saving the background color (maintain transparency). The files are in PNG format and I have been using Gimp 2 for Windows as well as Linux to perform the tasks manually.

However, I am curious if there is a way to crop all of the images from position 0,0 and 360x515 pixils either from a command line or a batch process?

share|improve this question
Just to add to the answer below, GIMP has a batch mode too. – Karan Jan 21 '13 at 19:34
up vote 2 down vote accepted

You can use Imagemagick's convert command to do this from the command line:

% convert 404.jpg -crop 250x250+0+0 404-new.jpg

Where 250x250 is the size of the region I want to crop and the beginning X & Y coordinates are (0,0).





You could call it in a shell script like so:

for file in `ls *.jpg`; do
  baseName = $(echo $file | cut -d"." -f1);
  convert $file -crop 360x515+0+0 ${file}-new.jpg;

See this link for more details:

share|improve this answer
That's everything except one thing. The images have a transparent background. Is there an extra switch to leave the background transparent. In gimp I have to uncheck "Save Background Color" to achieve this. – Neobane Jan 19 '13 at 5:27
Try adding the argument -transparent white. Change white to whatever color is your background. Look at man convert for more info. – slm Jan 19 '13 at 5:32
As it was, the image was already transparent and without any command, IM retained the transparency. Thank you. – Neobane Jan 19 '13 at 6:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .