Using Gimp 2.6.6 for MAC OS X (under X11) as downloaded from gimp.org.
I'm trying to automate a boring manual process with Script-Fu. I needed to parse the image file name to save off various layers as new files using a suffix on the original file name.
My original attempts went like this but failed because (string-search ...)
doesn't seem to be available under 2.6 (a change to the scripting engine?).
(set! basefilename (substring filename 0 (string-search "." filename)))
Then I tried to use this information to parse out the base file name using regex but (re-match-nth ...)
is not recognized either.
(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
(set! basefilename (re-match-nth orig-name buffer 1))
)
And while pulling the value out of the vector ran without error, the resulting value is not considered a string when it is passed into (string-append ...)
.
(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
(set! basefilename (vector-ref buffer 1))
)
So I guess my question is, how would I parse out the base file name?
Many thanks philcolbourn for pointing out a "simple" way to do this. Unfortunately, the butlast function is deprecated: http://www.gimp.org/docs/script-fu-update.html#deprecated
Here is philcolbourn's version with the suggested replacement:
Context
GIMP 2.6.6 Windows Vista SP2
Goal
Extract the basename of the original filename without its extension.
Symptom
Possible suggestion
GIMP menu "Filters" > "Script-Fu" > "Console"
In the input box, paste the following Script-Fu definition of function then hit the ENTER key:
To test the function, enter:
The Script-Fu Console answers:
My version splits the filename (f) into parts delimited by separator ("." in this case); drops last part; and re-combines them with separator again
so
and
As in Gimp 2.8 "gimp-image-get-uri" has to be used to get the filename of a JPG file, but gimp-image-get-uri delivers the complete path, I used this function to extract just the name of the pic (without the suffix ".jpg"):
(let* (
(uriname (car (gimp-image-get-uri IMAGE)))
(basename (car (reverse (strbreakup (car (strbreakup uriname ".")) "/"))))
...
)
...
)
Not really a correct solution:
A better implementation:
For those looking for a true string-replace functionality, here is a function I wrote for use in Script Fu