0

I'd like to write simple script that: 1) make image smaller by 25% (width 50%, height 50%), 2) adds watermark from another image (finally I'd like to set opacity for that to 20%).

My problem is that I'm not fully aware what I do with layers I create. Script works (but it was pain to make it work!) for bunch of files, I change parameters, but it seems I cannot get it to work as I want to). I see no watermark image - except when I do gimp-file-save for drawable2 (there's only watermark then).

May anyone help me with that? - and explain to me what I do wrong here?

 (define (add-watermark2 pattern waterm)


  (let* ((filelist (cadr (file-glob pattern 1))))
      (while (not (null? filelist))
          (let* ((filename (car filelist))
              (image (car (gimp-file-load RUN-NONINTERACTIVE filename filename)))
              (drawable   (car (gimp-image-active-drawable image)))
              (cur-width  (car (gimp-image-width image)))
              (cur-height (car (gimp-image-height image)))
              (width      (* 0.50 cur-width))
              (height     (* 0.50 cur-height))

              (gimp-image-scale image width height)   ; scale the image    

              (drawable2  (car (gimp-file-load-layer RUN-NONINTERACTIVE  image waterm)))
              (gimp-image-insert-layer image drawable2 0 -1) 
              (gimp-layer-set-offsets drawable2 100 100 )
              (gimp-layer-set-mode drawable2 0)
                (gimp-image-merge-visible-layers image 2)
          )

      (gimp-file-save   RUN-NONINTERACTIVE image drawable (string-append "w" filename) "")
  )
  (set! filelist (cdr filelist)) 
)))   
Zby.
  • 1

1 Answers1

0

The "save" operation to single-layer formats in the Gimp API applies to a "drawable" (usually, this is a layer). So to export your image you have to make a layer that represents the whole image. This is what you do with (gimp-image-merge-visible-layers image 2) but you are not using the layer returned by this call in the (gimp-file-save ...) call.

This said, for this kind of operations, ImageMagick is better/faster than Gimp, since it is designed to run from shell scripts.

xenoid
  • 8,396
  • 3
  • 23
  • 49