0

I have several hundred images I want to crop, unfortunately they are all of different sizes. I have a file that contains the correct cropping dimensions for each image called crop_dim. I want to supply this file to convert -crop using xargs or a bash script. This is what I have, but it doesn't work:

do
    cat crop_dim
    for i in {1..716} 
    convert -crop crop_dim%i *.jpg cropped_$d.jpg
done

I know this bash script is messed up in all sorts of ways, but I can't really put it all together. Thanks for the help.

  • You need a single loop that reads one line from the crop_dim file for each .jpg file - the trick will be to make sure the right crop is applied to the right file. Without knowing how the crop_dim file was generated (in particular, how the values are ordered with respect to the files) and how the .jpg files are named it's going to be hard for anyone to give more than an outline answer. – steeldriver Dec 4 '17 at 11:44
  • Thanks steeldriver. The order of lines in crop_dim is identical to the order of images in the file. Right now, crop_dim has only dimensions in it, but it could easily have a column of image names if those were needed to make a match. – GigaZaur Dec 4 '17 at 13:08

Your Answer

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

Browse other questions tagged or ask your own question.