如何使用 Script-Fu 解析基本文件名
使用适用于 MAC OS X(X11 下)的 Gimp 2.6.6(从 gimp.org 下载)。
我正在尝试使用 Script-Fu 将无聊的手动过程自动化。我需要解析图像文件名,以使用原始文件名的后缀将各个图层保存为新文件。
我最初的尝试是这样的,但失败了,因为 (string-search ...)
在 2.6 下似乎不可用(对脚本引擎的更改?)。
(set! basefilename (substring filename 0 (string-search "." filename)))
然后我尝试使用此信息 使用正则表达式解析基本文件名,但 (re-match-nth ...)
也无法识别。
(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
(set! basefilename (re-match-nth orig-name buffer 1))
)
虽然从向量中提取值没有错误,但结果值在传递到 (string-append ...)
时不被视为字符串。
(if (re-match "^(.*)[.]([^.]+)$" filename buffer)
(set! basefilename (vector-ref buffer 1))
)
所以我想我的问题是,我将如何解析基本文件名?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这并不是一个真正正确的解决方案:
更好的实现:
Not really a correct solution:
A better implementation:
上下文
GIMP 2.6.6 Windows Vista SP2
目标
提取原始文件名的基本名称,不带扩展名。
症状
可能的建议
GIMP 菜单“过滤器”> “Script-Fu”> “Console”
在输入框中粘贴以下 Script-Fu 函数定义
然后按ENTER键:
要测试该功能,请输入:
Script-Fu 控制台回答:
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:
我的版本将文件名(f)分割成由分隔符(在本例中为“.”)分隔的部分;丢弃最后一部分; 组合起来
再次将它们与分隔符重新
并
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
非常感谢 philcolbourn 指出了一种“简单”的方法来做到这一点。
不幸的是,butlast 函数已被弃用:
http://www.gimp.org/docs/script-fu-update .html#deprecated
这是 philcolbourn 的版本以及建议的替换:
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:
正如在 Gimp 2.8 中一样,必须使用“gimp-image-get-uri”来获取 JPG 文件的文件名,但 gimp-image-get-uri 提供完整路径,我使用此函数仅提取 JPG 文件的名称图片(不带后缀“.jpg”):(
让*(
(uriname(汽车(gimp-image-get-uri IMAGE)))
(basename(汽车(反向(strbreakup(汽车(strbreakup uriname“。”))“/”))))
...
)
...
)
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 ".")) "/"))))
...
)
...
)
对于那些寻找真正的字符串替换功能的人来说,这是我编写的用于 Script Fu 的函数
For those looking for a true string-replace functionality, here is a function I wrote for use in Script Fu