Switch to full style
Ask all general Gimp related questions here
Post a reply

Script-fu select outline of image inside png

Fri Jul 07, 2023 3:32 am

GIMP Version: 2.10.32
Operating System: Linux
GIMP Experience: New User

List any relevant plug-ins or scripts:
Script-fu



I have this script-fu code that selects the outline of my image, creates a path and saves it. This sometimes messes up when the image has transparency in it however:

Code:
(let* ((img (car ${loadLine}))
            (drawable (car (gimp-image-active-drawable img))))
            (gimp-image-select-item img 0 drawable)
            (plug-in-sel2path 0 img drawable)
            ${saveLine} (gimp-quit 0))


You can assume this works in most cased and the script is correct.

Now I've been trying to change it so that it selects all the pixels, even the semi-transparent ones, but I can't get it to work.

I've been trying this but it seems to break on getting the pixel:

Code:
(let* ((img (car ${loadLine}))
            (drawable (car (gimp-image-active-drawable img))))
  (if (= (car (gimp-drawable-has-alpha drawable)) 0)
    (begin
      (gimp-layer-add-alpha drawable)
      (gimp-edit-clear drawable)
    )
  )
  (gimp-context-set-opacity 100)
  (let* ((width (car (gimp-image-width img)))
         (height (car (gimp-image-height img))))
    (do ((y 0 (+ y 1)))
        ((= y height))
      (do ((x 0 (+ x 1)))
          ((= x width))
        (let* ((pixel (gimp-drawable-get-pixel drawable x y))
               (alpha (if (and (list? pixel) (>= (length pixel) 2)) (cadr pixel) 0)))
          (if (and (/= alpha 0) (/= alpha 255))
              (gimp-drawable-set-pixel drawable x y 4 (list 255 0 0 255))
          )
        )
      )
    )
  )
            (gimp-image-select-item img 0 drawable)
            (plug-in-sel2path 0 img drawable)
            ${saveLine} (gimp-quit 0))


Can anyone help me with my issue, by either fixing the issue with my new script or giving me another solution?
Thank you in advance

Re: Script-fu select outline of image inside png

Fri Jul 07, 2023 4:43 pm

Running such a thing pixel by pixel is going to be terribly slow. IMHO you can solve you problem by just thresholding the layer's alpha (plugin-threshold-alpha) before doing the selection.
Post a reply