Search code examples
gimpscript-fu

GIMP: Add padding to multiple images


I scanned a couple pages and edited them a little so the look neat.
But as I wanted to reprint them I noticed that I cropped the border from these images so that the printer won't print the whole content.

I have a Brother printer which has Linux drivers but somehow the scaling option does not work.
So I thought to scale the PDF (in which I have converted these scans) but the printer driver scales them back to fit the page. (If I disable the scale-to-fit option it becomes garbage)

So I thought that I could do some script-fu to resize these images with a couple of lines and add some padding for the printer. But I have no clue how to do this.

Here's my first attempt:

(define (resize-image filename-in filename-out )
  (let* ((image    (car (gimp-file-load RUN-NONINTERACTIVE filename-in "")))
         (drawable (car (gimp-image-active-drawable image)))
        )
     (gimp-image-resize image 2728 3819 124 173) 
     (gimp-file-save   RUN-NONINTERACTIVE image drawable filename-out "")
  )
)

This does not work. The image simply remains unchanged.

My page is A4 with 2480x3472, so I thought to add 10% to the width so it becomes 2728x3819 and set the offset to 5% so the content is centered (with offset values 124 and 173).


Solution

  • Wnen you resize the image you are just extending the canvas but not the layer. And gimp-file-save only saves the active "drawable" (layer in your case), so you just save the same image. What you have to do is either:

    • add a white layer at the bottom of the layer stack
    • flatten the image
    • save the result

    or

    • remove the layer's alpha channel (assuming the background paint color is white)
    • extend the layer to cover the canvas (the extension will be filled with white): gimp-layer-resize-to-image-size
    • save the result