Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
gimp-image-get-filename
#6
Hi teapot, thanks for trying it out  Smile

(10-08-2024, 05:39 AM)teapot Wrote: 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.

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
Whereas presumably what you want is gimp-image-get-name which will give test.xcf
Then you would need to strip off the .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)
        (set! newFileName (string-append inDir
                pathchar (car (strbreakup (car (gimp-image-get-name image)) ".")) ".webp"))
       )

but... (yes there is a "but"  Big Grin )  "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

   

Result using "gimp-image-get-name", it export the "temporary?" name in GIMP

   

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...

   

The problem with car, cdr, cddr, cadar, and so on.. first is, that I have a very hard time to get it  Sad ,
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  Rolleyes
-------------------------
(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  Big Grin

(10-08-2024, 05:39 AM)teapot Wrote: Any reason why you aren't using python?

The 1 Trillion dollar question   Blush

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...MP-at-once
Then add more option ➤ https://www.gimp-forum.net/Thread-Batch-...re-options
Then change the way the script works + a suggestion to reverse order by Krikor ➤ https://www.gimp-forum.net/Thread-Export...r-settings
Then a suggestion to add an option from Michael Schumacher on reddit ➤ https://www.gimp-forum.net/Thread-Batch-...3-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  Big Grin

Today I just want to finish this part, and "never" come back to it again if possible  Wink

(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  Big Grin
Thank you Ofnuts.
Patrice
Reply


Messages In This Thread
gimp-image-get-filename - by PixLab - 10-07-2024, 07:36 AM
RE: gimp-image-get-filename - by Ofnuts - 10-07-2024, 11:01 PM
RE: gimp-image-get-filename - by PixLab - 10-08-2024, 04:00 AM
RE: gimp-image-get-filename - by Ofnuts - 10-08-2024, 07:22 AM
RE: gimp-image-get-filename - by teapot - 10-08-2024, 05:39 AM
RE: gimp-image-get-filename - by PixLab - 10-09-2024, 05:14 AM
RE: gimp-image-get-filename - by rich2005 - 10-09-2024, 08:37 AM
RE: gimp-image-get-filename - by PixLab - 10-09-2024, 01:14 PM
RE: gimp-image-get-filename - by teapot - 10-09-2024, 04:28 PM
RE: gimp-image-get-filename - by PixLab - 10-10-2024, 09:44 AM
RE: gimp-image-get-filename - by teapot - 10-10-2024, 06:48 PM
RE: gimp-image-get-filename - by PixLab - 10-30-2024, 06:37 AM

Forum Jump: