It is currently Thu Jun 27, 2024 6:45 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Script-fu select outline of image inside png
PostPosted: Fri Jul 07, 2023 3:32 am  (#1) 
Offline
New Member

Joined: Jul 07, 2023
Posts: 1
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


Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Script-fu select outline of image inside png
PostPosted: Fri Jul 07, 2023 4:43 pm  (#2) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4750
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.

_________________
Image


Top
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Selecting outline of image

2

No new posts Get a mouse click or select a pixel in an image in a python plugin?

3

No new posts Attachment(s) Need outline help

9

No new posts Attachment(s) Outline Layer Contents by Ofnuts

2

No new posts How do I keep the outline smooth on transparent text GIF?

2



* Login  



Powered by phpBB3 © phpBB Group