[tutorial] gimp script to batch resize, add border, watermark or signature

Hi all !

Right here a brand new tutorial I made for you.

Purpose:
You need to batch lots of photos that need an automatic resize, or need a border, watermark/signature on it.
Without Photoshop, but with free open source software and an easy script (like a macro or photoshop action).
The script automatically detects if your photo is landscape, portrait or square, and resizes according to that.

What you need is:

  • Gimp (free, works in Linux and Windows too)
  • A simple script I wrote, below in this tutorial
  • BIMP (optionally if you want to batch you can link to the script)

Now get started!

First of all, we need to make a template image. You need a transparent one and save it as .png.
If you want a border, a watermark or a signature, you can all add them in that template.
Make a template image for horizontal, vertical and square photos.

Create a Script for GIMP and save it as .scm
The script shown below, needs to be modified to your needs.
Modify the size your images need to have, according to the template image you previously made (longest and shortest side of the photo, see comments in the script).
Define the path where your template images are saved.
For Linux users, the path will be different and won’t start with C:/, but most possible with /home/username/…

(define (Make-Border image drawable)
    (let* (
            ; variables you can modify yourself:
            (long 800)    ; define the value in pixels of the longest length you want your image to have (the horizontal length of a landscape photo)
            (short 532)   ; define the value in pixels of the shortest length you want your image to have (the vertical length of a landscape photo)
            (horipath "C:/Fotos/Hori.png")     ; define path of border image for horizontal photos 
            (vertipath "C:/Fotos/Verti.png")   ; define path of border image for vertical photos
            (squarepath "C:/Fotos/Square.png") ; define path of border image for square photos
            ; other vars you shouldn't modify:
            (wval  (car (gimp-image-width image)))
            (hval (car (gimp-image-height image)))
            (back-layer 0)
       )
   (if (> hval wval)            ; check if verti
            (begin
            (gimp-image-scale image short long)
            (set! back-layer(car (gimp-file-load-layer RUN-NONINTERACTIVE image vertipath)))
            )
       )
   (if (< hval wval)            ; check if hori
            (begin
            (gimp-image-scale image long short)
            (set! back-layer(car (gimp-file-load-layer RUN-NONINTERACTIVE image horipath)))
            )
       )
   (if (= hval wval)            ; check if square
            (begin
            (gimp-image-scale image short short)
            (set! back-layer(car (gimp-file-load-layer RUN-NONINTERACTIVE image squarepath)))
            )
       )
    (gimp-image-insert-layer image back-layer -1 0)
    (gimp-displays-flush)
  )
)
(script-fu-register "Make-Border"
                    "Auto-resize, create layer, add border, done!"
                    "Script by Bulevardi"
                    "Copyright (C) 2015 Bulevardi"
                    "BLVD i"
                    "Version 0.1"
                    "*"
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
)
(script-fu-menu-register "Make-Border" "<Image>/Bulevardi Scripts/")

For Windows users, save this script in:
C:\Users\MyUserName.gimp-2.8\scripts\myscript.scm
The menu will auto attach in your Gimp menubar when restarting Gimp.

For Linux users, just save the .scm in a folder where you store your scripts.
Then in Gimp, click on Preferences, than Folders, and finally Scripts.
Do a refresh by clicking the menu Filters, then on Script-Fu, and finally Refresh Scripts from the image menubar.
The script will now appear in one of your menus.

Now, when restarting GIMP, your script appears here:

Open a photo, and click on the script to run the process, your photo will get resized and framed into this border:

But how to batch?

Here you need BIMP, a plugin that can do lots of stuff.
You choose a folder where your photos are stored, you choose a folder where they need to be saved, and you choose this script you just made to automate the border you want !

Enjoy and let me know if it works out :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.