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?

  • Just to add to the answer below, GIMP has a batch mode too. – Karan Jan 21 '13 at 19:34

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: http://www.imagemagick.org/Usage/crop/

  • 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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