GIMP Chat
http://gimpchat.com/

Script-fu select outline of image inside png
http://gimpchat.com/viewtopic.php?f=8&t=20429
Page 1 of 1

Author:  Forsaken [ Fri Jul 07, 2023 3:32 am ]
Post subject:  Script-fu select outline of image inside png

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:

(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:

(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

Author:  ofnuts [ Fri Jul 07, 2023 4:43 pm ]
Post subject:  Re: Script-fu select outline of image inside png

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.

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/