Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gimp-image-get-filename
#11
(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")
Reply
#12
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
Patrice
Reply


Forum Jump: