It is currently Sat Jul 13, 2024 10:33 am


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: [SOLVED] I need a working example of file_*_save in Windows XP Pro
PostPosted: Tue Apr 02, 2013 6:26 pm  (#1) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
I am trying to save a sequence of files to my XP Pro and I need a working example of how to do that with one of the many file_*_save procedures. I am using file_gif_save as a first attempt to keep it simple. I've got, so far,

    pdb.file_gif_save(
        1, my_image,my_layer,
        "C:\Documents and Settings\User\My Documents\My Pictures\TEST.gif",
        "C:\Documents and Settings\User\My Documents\My Pictures\TEST.gif",
        0,0,0
        )


I'm not getting any error messages, but I'm not getting saved files either. I see a few clues applying the module "os", but otherwise I can't get a handle on what is going on.

Any tips, clues or documentation would be appreciated.


Last edited by Grafx on Thu Apr 04, 2013 2:35 pm, edited 1 time in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: I need a working example of file_*_save in Windows XP Pro
PostPosted: Tue Apr 02, 2013 9:10 pm  (#2) 
Hi,
I did a search of my .py files and found the attached.
I think it has an example of what you need.
Cheers


Top
 Post subject: Re: I need a working example of file_*_save in Windows XP Pro
PostPosted: Wed Apr 03, 2013 12:48 am  (#3) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
Your problem is almost certainly the backslashes. You would need escape them to make the file name strings:
pdb.file_gif_save(
        1, my_image,my_layer,
        "C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
        "C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
        0,0,0
        )


Top
 Post subject: Re: I need a working example of file_*_save in Windows XP Pro
PostPosted: Wed Apr 03, 2013 2:10 am  (#4) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
paynekj wrote:
Your problem is almost certainly the backslashes. You would need escape them to make the file name strings:
pdb.file_gif_save(
        1, my_image,my_layer,
        "C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
        "C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
        0,0,0
        )

The first argument (interactive/non-interactive) is implicit and shouldn't be specified...

_________________
Image


Top
 Post subject: Adding slashes didn't work
PostPosted: Wed Apr 03, 2013 12:37 pm  (#5) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
I tried adding the slashes as suggested so now the code is like,

Quote:
pdb.file_gif_save(
1, my_image,my_layer,
"C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
"C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
0,0,0
)


But this still doesn't get me a written file.

ofnuts, please explain,

Quote:
The first argument (interactive/non-interactive) is implicit and shouldn't be specified...


From the procedure browser for the first argument:

Quote:
run-mode INT32 The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }


It seems like there is an option there, why would it be implicit and not specified?

Another thing I am confused about is the arguments "image" and "drawable". Which is being save to the file? The "drawable", I assume is a layer. What else could a "drawable" be? Are both to be specified or only one?


Top
 Post subject: Re: I need a working example of file_*_save in Windows XP Pro
PostPosted: Wed Apr 03, 2013 2:18 pm  (#6) 
Offline
Script Coder
User avatar

Joined: Jun 22, 2010
Posts: 1171
Location: Here and there
I may not be Ofnuts, but here's something from me while you're waiting...

If you're trying to save an image as a GIF, then make sure you have converted the image to indexed mode before trying to save it, otherwise you get this error message:
Cannot save RGB colour images. Convert to indexed colour or greyscale first.


The code I had to successfully save the image was this:
def kp24_test(my_image, my_layer):
 
    FilePath = "C:\\Documents and Settings\\Owner\\My Documents\\My Pictures\\TEST.gif"
    pdb.gimp_message(FilePath)
    pdb.file_gif_save(my_image,my_layer,FilePath, FilePath,0,0,0,0)

    gimp.displays_flush
       

register(
    "python-fu-kp24_test",
    "Test",
    "Enhancement of 'meaningful black' (Version 0.7)",
    "Meetthegimp-Community http://forum.meetthegimp.org/index.php/topic,42",
    "GPL License",
    "2008",
    "<Image>/contributed/Test (Python New)",
    "*",
    [
    ],
    [],
    kp24_test
)


Kevin


Top
 Post subject: Re: Adding slashes didn't work
PostPosted: Wed Apr 03, 2013 3:25 pm  (#7) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
Grafx wrote:
I tried adding the slashes as suggested so now the code is like,

Quote:
pdb.file_gif_save(
1, my_image,my_layer,
"C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
"C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.gif",
0,0,0
)


But this still doesn't get me a written file.

ofnuts, please explain,

Quote:
The first argument (interactive/non-interactive) is implicit and shouldn't be specified...


From the procedure browser for the first argument:

Quote:
run-mode INT32 The run mode { RUN-INTERACTIVE (0), RUN-NONINTERACTIVE (1) }


It seems like there is an option there, why would it be implicit and not specified?

Another thing I am confused about is the arguments "image" and "drawable". Which is being save to the file? The "drawable", I assume is a layer. What else could a "drawable" be? Are both to be specified or only one?

1) Interactive/non-interactive: the plugin needs to know (maybe) but if you call it from code it is obviously not interactive... so its filled for you by the PDB interface.
2) Technically a drawable is a layer or a channel. Technically also, you may have cases where you save only one of the layers (or a channel). How plugin reacts to this parameter is up to them.

_________________
Image


Top
 Post subject: Re: Adding slashes didn't work
PostPosted: Wed Apr 03, 2013 5:01 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Apr 23, 2010
Posts: 1553
Location: not from Guildford after all
Grafx wrote:
Another thing I am confused about is the arguments "image" and "drawable". Which is being save to the file? The "drawable", I assume is a layer. What else could a "drawable" be? Are both to be specified or only one?

A drawable can be one of a layer, a layermask, or a channel. When you run a 'file-*-save' non-interactively, whether the 'drawable' parameter is respected depends upon the plug-in being used.

'file-gif-save' always ignores the drawable parameter and saves all layers (ignoring any layermasks). If the image is not in Indexed mode than an error results. Alpha channels are thresholded to either opaque or transparent.

'file-png-save' will only save the specified drawable. The drawable may or may not have an alpha channel, and the image can be in RGB, GRAYSCALE, or INDEXED mode. Indexed mode PNG saves (unfortunately) treat the alpha channel identically to GIF saves (rather than the more capable PNG standard for Indexed alpha channels).

'file-jpg-save' will only save the specified drawable, and if the layer has an alpha channel then it is ignored. If the image is in Indexed mode then an error results.

If I recall correctly, prior to version 2.8 the above behavior was in some cases different than described above (for example, saving multi-layer images to PNG or JPG resulted in an error).

Because of the above inconsistencies, when exporting to non-XCF formats in a script it is generally a good idea to create a temporary image which you can modify so as to satisfy any and all limitations of the targeted file format.

_________________
Any sufficiently primitive technology is indistinguishable from a rock.


Last edited by saulgoode on Wed Apr 03, 2013 6:43 pm, edited 1 time in total.

Top
 Post subject: Success!
PostPosted: Wed Apr 03, 2013 6:35 pm  (#9) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
Thanks to all who posted.

I have managed to save a file. I will post a demo plug-in as soon as I get it going.


Top
 Post subject: Re: I need a working example of file_*_save in Windows XP Pro
PostPosted: Thu Apr 04, 2013 2:34 pm  (#10) 
Offline
GimpChat Member

Joined: Mar 15, 2013
Posts: 36
OK, I applied the suggested code, except I changed the file_gif_save to file_png_save because I was having problems trying to convert the image to INDEXED color.

#!/usr/bin/python
from gimpfu import *

def test_image(size, color) :
      
   img = gimp.Image(size, size, RGB)
   lyr = gimp.Layer(img, "Uni Layer", size, size,
        RGB_IMAGE, 100, NORMAL_MODE)
   img.disable_undo()
   img.add_layer(lyr, 0)
   gimp.set_background(color)
   pdb.gimp_edit_fill(lyr, BACKGROUND_FILL)
   pdb.gimp_display_new(img)
   pdb.gimp_image_undo_enable(img)
   
   FilePath = "C:\\Documents and Settings\\User\\My Documents\\My Pictures\\TEST.png"
   pdb.gimp_message(FilePath)
   pdb.file_png_save(
       img,
       lyr,
       FilePath,
       FilePath,
       0,0,0,0,0,0,0
       )
   gimp.displays_flush    # disp = gimp.Display(img)

register(
   "test_image",
   "This is a test",
   "This is a test",
   "Name Test",
   "Name Test",
   "Date Test",
   "Orange Image TEST",
   "",
   [
      (PF_INT, "size", "Size", 100),
      (PF_COLOR, "color", "Image", (255, 127, 0))
   ],
   [],
   test_image,
   menu="<Image>/MyScripts"
   )

main()


And we see in code that a message is to pop up showing what Python sees the FilePath as being which is,

C:\Documents and Settings\User\My Documents\My Pictures\TEST.png


This code is adapted from code I had asked about earlier in another post here with a different problem,

viewtopic.php?f=9&t=6700&start=20

All fixed. Thanks again to those who posted.


Top
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Where did GIMP save my file, & how do I change default save location

5

No new posts Attachment(s) Save For Web Gimp 2.8 Windows

5

No new posts Attachment(s) Gimp tries to save a composed image to windows system32 by default

1

No new posts I got G'MIC working in the new GIMP version 2.10.24 (Windows 64 only)

4

No new posts Attachment(s) Layers in second windows 10 account not working properly

3



* Login  



Powered by phpBB3 © phpBB Group