Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 1 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).

Before

before

After

after

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;
done

See this link for more details: http://www.imagemagick.org/Usage/crop/

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.