title: How do I write a custom auto-crop script using the GIMP?
body: <p>I have a bunch of screen shots and I'd like to crop out the window border. I would like to crop them all using a script. </p>
  
  <p>I have access to the GIMP, but not photoshop so I assumed that the GIMP would be the best tool to use. I have not scripted with the GIMP before, so I looked up some GIMP crop scripts. The ones I found are all similar to what I want, but not quite. I thought it would be a simple matter to alter the script to what I need. But since I am not familiar with the scripting language it is proving more difficult than I thought. I found a great auto crop script <a href="http://rocksun.cn/gimp-crop-script/" rel="noreferrer">here</a>. Can someone help me customize it for what I need?</p>
  
  <pre><code>    (define (script-fu-rs-center-crop filename outfilename width height)
  
    (let* ((image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
            (drawable (car (gimp-image-get-active-layer image))))
            (let* ((original-width (car (gimp-image-width image)))
                 (original-height (car (gimp-image-height image)))
                 (new-width original-width)
                 (new-height original-height)
                 (offset-x 0)
                 (offset-y 0))
  
                 (if (&lt;= (/ original-width original-height) (/ width height))
                     (gimp-image-crop image original-width (* original-width (/ height width)) 0 (/ (- original-height (* original-width (/ height width))) 2) )
                     (gimp-image-crop image (* original-height (/ width height)) original-height (/ (- original-width (* original-height (/ width height))) 2) 0)
                 )
             )
  
    (set! drawable (car (gimp-image-get-active-layer image)))
  
  (gimp-file-save RUN-NONINTERACTIVE image drawable outfilename outfilename)
       (gimp-image-delete image)))
  </code></pre>
  
  <p>The overall dimensions are not the same for all the photos. But they do all have the same number of pixels on the top, left, right and bottom that I want to crop out. So let's say the image has pixel dimensions <code>width</code> and <code>height</code> and I want to remove <code>t_junk</code> pixels off the top, <code>b_junk</code> pixels off the bottom, <code>l_junk</code> pixels off the left, and <code>r_junk</code> pixels off the right. So I want the new image dimensions to be <code>width - l_junk - r_junk</code> and <code>height - t_junk - b_junk</code>.</p>