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
|
gimp-image-get-filename - PixLab - 10-07-2024 I got errors when trying to set the original name, what did I missed? It seems to be from the second "if" (first one works fine) "pathchar (car (gimp-image-get-filename image)) ".webp"))" BTW is there a "else" or sort of in scheme? Code: (while (> i 0) [attachment=12429] RE: gimp-image-get-filename - Ofnuts - 10-07-2024 file-webp-save2 takes 19 arguments and you are only showing 2. RE: gimp-image-get-filename - PixLab - 10-08-2024 (10-07-2024, 11:01 PM)Ofnuts Wrote: file-webp-save2 takes 19 arguments and you are only showing 2. They are all there, see below last code section, i did put the full code The thing is if I use only (while (> i 0) (set! image (vector-ref (cadr (gimp-image-list)) (- i 1))) (if (= KeepName 0) (set! newFileName (string-append inDir pathchar inFileName (substring "0000000" (string-length (number->string (+ inFileNumber i)))) (number->string (+ inFileNumber (- ii i))) ".webp")) ) This part works as intended, (if (= KeepName 0) ➤ it's for if SF-TOGGLE "Keep the original name" FALSE but if I add the below code, that part below throw an error when the SF-Toggle is checked > SF-TOGGLE "Keep the original name" TRUE (if (= KeepName 1) (set! newFileName (string-append inDir pathchar (car (gimp-image-get-filename image)) ".webp")) ) i would like to concatenate the path + original image name + extension (here webp), It is to propose if user wants to keep the original image name or not, I also read there > https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpimage.html#gimp-image-get-filename that "gimp-image-get-filename" returns The filename. The returned value must be freed with g_free(). What does it mean "must be freed with g_free()"? what is g_free()? The full script Code: (define (script-fu-pxl-save-all-images-as-webp inDir inAskAfter inKeepName inFileName inFileNumber inPreset inLossLess inQuality inAlphaQuality inAnimation inLoop inMiniSize inKeyframe inExif inIPTC inXMP inThumbnail inDelay inForceDelay runChoice) RE: gimp-image-get-filename - teapot - 10-08-2024 Hi PixLab, I gave it a try on linux. Ran your script on image /home/teapot/test.xcf with export directory /home/teapot/Desktop/ With 'Keep the original name' un-ticked got newFileName /home/teapot/Desktop/IMAGE-0000001.webp which looks OK. With 'Keep the original name' ticked got newFileName /home/teapot/Desktop//home/teapot/test.xcf.webp This is not OK, the path is in 'twice' and there's a .xcf. gimp-image-get-filename gives the whole path so /home/teapot/test.xcf Whereas presumably what you want is gimp-image-get-name which will give test.xcf Then you would need to strip off the .xcf Also you should consider the case when the user has a brand new .xcf file that's never been saved. Any reason why you aren't using python? RE: gimp-image-get-filename - Ofnuts - 10-08-2024 (10-08-2024, 04:00 AM)PixLab Wrote: I also read there > https://developer.gimp.org/api/2.0/libgimp/libgimp-gimpimage.html#gimp-image-get-filename You are looking at the doc for the C API. For script-fu, stick to the doc in the script-fu console, much less confusing (the C doc also contains a lot of calls that aren't available in script-fu. RE: gimp-image-get-filename - PixLab - 10-09-2024 Hi teapot, thanks for trying it out (10-08-2024, 05:39 AM)teapot Wrote: With 'Keep the original name' ticked got newFileName /home/teapot/Desktop//home/teapot/test.xcf.webp You did not get an error? I mean, the script as it is throw an error if "Keep the original name" is ticked, at least on my distro (Ubuntu-MATE 20.04 /GIMP 2.10.38) I found a partial "solution" but ... see below the code (10-08-2024, 05:39 AM)teapot Wrote: gimp-image-get-filename gives the whole path so /home/teapot/test.xcf Thanks for the "gimp-image-get-name" it worked, I did find a partial solution with "strbreakup" to remove any file extension and add the extension I want, see code below. Code: (if (= isKeepName 1) but... (yes there is a "but" ) "gimp-image-get-name" take the temporary name in GIMP when we drag and drop images in GIMP For instance if I drag and drop an image with the name "MyImage.jpg", in GIMP it will be called "[Myimage] (Imported)" and it is this name that GIMP will export with "gimp-image-get-name" ➤ [Myimage] (Imported).jpg Drag and drop MyImage.jpg in GIMP look at the name [attachment=12432] Result using "gimp-image-get-name", it export the "temporary?" name in GIMP [attachment=12433] So, I'm telling myself that I need to use "gimp-image-get-filename", and get the name before the extension in the "list?". There is another problem, on *nix system we can have names with multiple dot/period (and certainly on Windows nowadays), if I use (car (strbreakup (car (gimp-image-get-name image) ".") on an image named "this.is.my.image.xcf", I will only get "this" in the name... [attachment=12434] The problem with car, cdr, cddr, cadar, and so on.. first is, that I have a very hard time to get it , second I did not find any explanations to fetch the last in the list or the one before the last, they (websites) are all speaking about fetching/catching the first in the list and the remaining list after the first. If I can find out how to get only the name with this code just by using the right combination of "car" / "cdr" / "caaddr" / "whatnot", to get the one before the last (the extension) in the "list" that would be a huge step for me ------------------------- (if (= isKeepName 1) (set! newFileName (string-append inDir pathchar (car (strbreakup (car (gimp-image-get-filename image)) ".")) ".webp")) ) ----------------------- (10-08-2024, 05:39 AM)teapot Wrote: Also you should consider the case when the user has a brand new .xcf file that's never been saved. Indeed, you're right, but I'm a slow person, one thing at a time (10-08-2024, 05:39 AM)teapot Wrote: Any reason why you aren't using python? The 1 Trillion dollar question All started with with a simple saule goode script which was saving the active layer, it was an scm. then rich2005 opened my eyes ➤ https://www.gimp-forum.net/Thread-Export-all-opened-images-in-GIMP-at-once Then add more option ➤ https://www.gimp-forum.net/Thread-Batch-export-all-opened-images-at-once-V2-more-options Then change the way the script works + a suggestion to reverse order by Krikor ➤ https://www.gimp-forum.net/Thread-Export-ALL-opened-images-in-GIMP-at-once-with-your-settings Then a suggestion to add an option from Michael Schumacher on reddit ➤ https://www.gimp-forum.net/Thread-Batch-export-all-opened-images-in-GIMP-at-once-V3-22343567 Then few days ago I "updated" on my gitlab to make it compatible for GIMP 3 (I did not test yet) Then I recall that many people asked to be able to save with the original name... thus I get caught in that spiral down of the scheme scripting Today I just want to finish this part, and "never" come back to it again if possible (10-08-2024, 07:22 AM)Ofnuts Wrote: You are looking at the doc for the C API. For script-fu, stick to the doc in the script-fu console, much less confusing (the C doc also contains a lot of calls that aren't available in script-fu. Looks like I get lost during my searches Thank you Ofnuts. RE: gimp-image-get-filename - rich2005 - 10-09-2024 (10-09-2024, 05:14 AM)PixLab Wrote: ....snip..... 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. I did download a couple, and one that works (at least it does here with 2.99.19 appimage) is attached. This is a script-fu plugin. Goes in the plugins folder in its own folder, has to be executable. Backs up at intervals. and saves a .xcf in a ~/Autosaved folder. Registers bottom of the File menu. [attachment=12436] There are lines in the script for vector and for making a file name.ext so it might help. The python examples I have seen look horribly complicated to me, but then I am only a dabbler. A proper "macro" would be nice, but that is only mentioned for the dim-and-distant-future. In Gimp glacial development terms, I do not think I will be around to see that RE: gimp-image-get-filename - PixLab - 10-09-2024 (10-09-2024, 08:37 AM)rich2005 Wrote:(10-09-2024, 05:14 AM)PixLab Wrote: ....snip..... Oh... indeed it helps a lot for GIMP 3, I already saw few things that I need to update on my "updated GIMP 3" version ASAP Also I was not aware we need to put in a folder and give permissions Thank you very much rich2005 for that invaluable info and a working GIMP 3 script to study RE: gimp-image-get-filename - teapot - 10-09-2024 (10-08-2024, 04:00 AM)PixLab Wrote: I did not find any explanations to fetch the last in the list or the one before the last, they (websites) are all speaking about fetching/catching the first in the list and the remaining list after the first. Well you could reverse the list. Or getting the last element of the list without reversing it: Code: (let* ((l '(3 45 4 "abc" "def")) There's some ideas here but they aren't very robust: https://stackoverflow.com/questions/1386293/how-to-parse-out-base-file-name-using-script-fu Personally I'd be doing this in Python using os: Code: $ python2 RE: gimp-image-get-filename - PixLab - 10-10-2024 (10-09-2024, 04:28 PM)teapot Wrote: Well you could reverse the list. Or getting the last element of the list without reversing it: 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 (10-09-2024, 04:28 PM)teapot Wrote: There's some ideas here but they aren't very robust: 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 I was not able to make one of them works, but it's my extremely limited knowledge (if I can call "knowledge") about it. In all case thank you very much teapot |