Gimp-Forum.net
gimp-image-get-filename - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: gimp-image-get-filename (/Thread-gimp-image-get-filename)

Pages: 1 2


RE: gimp-image-get-filename - teapot - 10-10-2024

(10-10-2024, 09:44 AM)PixLab Wrote: Thanks, ok I understood how it works in the Script-fu console, not sure how to adapt it to the gimp-image-get-filename, nor understand what's the ' in front of the parenthesis

It's just to make a list to have something to play with:
    '(3 45 4 "abc" "def")

(10-10-2024, 09:44 AM)PixLab Wrote: not a lot about script-fu on internet, or things are from 20 years ago ➤ we all go by the same different results in google  Big Grin I was not able to make one of them works, but it's my extremely limited knowledge (if I can call "knowledge") about it.

Yes it's all old and much of it like strbreakup that you used in post #6 are deprecated. I don't know when that is due to happen. That said I'm not up to writing replacements as my knowledge is limited too Smile

Here's my try, it just prints the resulting name in a gimp message. It doesn't handle unusual cases, like no filename or no file extenstion and uses deprecated code.

Code:
; To look at PixLab's questions from here:
;     https://www.gimp-forum.net/Thread-gimp-image-get-filename
; See also:
;    https://stackoverflow.com/questions/1386293/how-to-parse-out-base-file-name-using-script-fu

; ‘strbreakup’ and ‘unbreakupstr’ are not standard Scheme.
; Neither is ‘last’, which is defined as (cons (car (reverse x)) '()).
; They are defined in /usr/share/gimp/2.0/scripts/script-fu-compat.init
; That file contains TinyScheme code which implements functions provided by its
; predecessor, SIOD.  It says at the start that all the routines other than
; the random-number ones at the start are deprecated.

(define (script-fu-pixlab-test-filename image)

  (let* ((filename (car (gimp-image-get-filename image)))

         ; Split on slashes and set name to the last element.
         ; Will fail in unusual cases e.g. unsaved xcf files don't have a filename.
         ; Assumes the filename has a file extension.
         ; Assumes linux.
         ; strbreakup is deprecated but you were already using it in post #6.
         (l1 (strbreakup filename "/"))
         (len1 (length l1))
         (name (list-ref l1 (- len1 1)))

         ; Alternative.
         ; last does a reverse.
         ; last is deprecated.
         ; (name (car (last (strbreakup filename "/"))))

         ; Copied from stackoverflow.
         ; Works for names with more than one dot.
         ; unbreakupstr is deprecated.
         (name-less-extension (unbreakupstr (reverse (cdr (reverse (strbreakup name ".")))) "."))

        )

  (gimp-message name-less-extension)))

(script-fu-register
  "script-fu-pixlab-test-filename"           ; Name
  "Pixlab Test Filename"                     ; Menu label
  "Random things tried out in scheme."       ; Description
  "Anon"                                     ; Author
  "Anon"                                     ; Copyright
  "2024"                                     ; Date
  "*"                                        ; Types
  SF-IMAGE      "image"           0
)

(script-fu-menu-register "script-fu-pixlab-test-filename" "<Image>/Script-Fu")



RE: gimp-image-get-filename - PixLab - 10-30-2024

Shame on me Confused , I'm sorry teapot, I "kind" of forgot to answer in this thread as I put this script on stand by, too many time spent on it for no result but raising my arterial blood stream pressure... Blush

In all case thank you so very much for ALL your help


RE: gimp-image-get-filename - pixelmixer - 11-21-2024

(10-09-2024, 08:37 AM)rich2005 Wrote: Maybe script-fu is the simpler alternative for users.  There are (were) Gimp 3 examples around:
https://discourse.gnome.org/t/gimp-3-plugins-and-script-fu-examples/15114  and the link to the scripts worked a couple of weeks ago, looks like it has been pulled, probably changes to syntax, who-knows.

Hello,

Discourse freezes comments, so the original link is now permanently inactive.
Previously, there was a detailed Script-Fu blog created before I gained more knowledge about building websites.

Here is the updated version:
https://script-fu.github.io/funky/

It’s a beginning. More sections will be added over time, and it will eventually become a comprehensive resource for Script-Fu.

I have come to appreciate Script-Fu and believe it has untapped potential. In Artbox, I discovered how to add extra functions to expand Script-Fu's capabilities. Although I am interested in learning Python, Script-Fu—along with loading libraries, definitions, and custom syntax highlighters—is fun.

Thanks