It is currently Wed Oct 18, 2017 3:01 pm


Latest GIMP Scripts & Plug-ins

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Script to save already open png file and exit
PostPosted: Fri Oct 06, 2017 4:58 pm  (#1) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
Hi,

I have written a simple script in Scene or .scm to save an already open filename to png format and then exit gimp.

Sounds simple enough but i'm struggling.

I can't manage to get the parameters in "file-png-save" or somewhere else right.

All it has to do is save the already open png file and exit.

I'm fairly sure the below code is rubbish, so please liberally delete as necessary

Thanks

(define (script-fu-save-png Image layer)
   (gimp-displays-flush)
   (file-png-save RUN-NONINTERACTIVE Image layer filename filename FALSE 9 FALSE FALSE FALSE FALSE FALSE)
   (gimp-quit)
)

(script-fu-register
   "script-fu-save-png"
   "<Image>/Save PNG & Exit"
   "Save PNG file and exit GIMP."
   "kes"
   "kes"
   "October 2017"
   "RGB*, GRAY*, INDEXED*"
   SF-IMAGE         "Image" 0
   SF-DRAWABLE   "Layer" 0
)


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: Script to save already open png file and exit
PostPosted: Fri Oct 06, 2017 6:29 pm  (#2) 
Online
Script Coder
User avatar

Joined: May 07, 2014
Posts: 2861
Location: Tin from Victoria BC Canada
try this:
(define (script-fu-save-png Image layer)
   (gimp-displays-flush)
   (define filename (car (gimp-image-get-filename Image)))
   (file-png-save RUN-NONINTERACTIVE Image layer filename filename FALSE 9 FALSE FALSE FALSE FALSE FALSE)
   (gimp-quit 1)
)

(script-fu-register
   "script-fu-save-png"
   "<Image>/Save PNG & Exit"
   "Save PNG file and exit GIMP."
   "kes"
   "kes"
   "October 2017"
   "RGB*, GRAY*, INDEXED*"
   SF-IMAGE         "Image" 0
   SF-DRAWABLE   "Layer" 0
)

_________________
T.
Image gimplearn.net                                                                           


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 3:07 am  (#3) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 3656
There is a shorter script: Ctrl-E, Ctrl-Q, Ctrl-D. :)

_________________
Image


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 6:58 am  (#4) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
Thanks @trandoductin. That did it. Thanks


Last edited by kes on Sat Oct 07, 2017 7:08 am, edited 3 times in total.

Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 6:59 am  (#5) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
ofnuts wrote:
There is a shorter script: Ctrl-E, Ctrl-Q, Ctrl-D. :)


Thanks @ofnuts. That's not the way I want to do it.


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 7:13 am  (#6) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
Is there a way I can attach a custom shortcut key to that new script menu item within gimp e.g. CTRL-X, or some other available shortcut sequence.

--> I figured it out guys. I moved the Script menu item "save PNG & Exit" into File, and was able to access it under > Edit > Keyboard shortcuts <--

Thanks for your help


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 8:57 am  (#7) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
I've improved the idea and am getting the hang of this more.
But I'm back to being unable to save again.
What you see works until "file-png-save" at the end.
I've tried to re-define the Image, Layer & Drawable though have clearly not succeeded. They are now commented out.
After merging the three layers, why can't I save them?
I've read that Python-Fu is easier to use. Would this easier to convert to Python?

(define (script-fu-save-png Image layer)
   (gimp-displays-flush)
   (define filename (car (gimp-image-get-filename Image)))
   (define drawable (car (gimp-image-get-active-drawable Image)))
   (script-fu-round-corners Image drawable 20 TRUE 0 0 15 TRUE FALSE)
   (gimp-image-merge-visible-layers Image 0)
   
   ;(define layer (car (gimp-image-get-layer Image)))   
   ;(define drawable (car (gimp-image-get-active-drawable Image)))
   (file-png-save RUN-NONINTERACTIVE Image layer filename filename FALSE 9 FALSE FALSE FALSE FALSE FALSE)
   ;(gimp-quit 1)
)

(script-fu-register
   "script-fu-save-png"
   "<Image>/File/Save PNG & Exit"
   "Save PNG file and exit GIMP."
   "kes"
   "kes"
   "October 2017"
   "RGB*, GRAY*, INDEXED*"
   SF-IMAGE         "Image" 0
   SF-DRAWABLE   "Layer" 0
)


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 9:39 am  (#8) 
Online
Script Coder
User avatar

Joined: May 07, 2014
Posts: 2861
Location: Tin from Victoria BC Canada
instead of
(gimp-image-merge-visible-layers Image 0)


you need to set layer to be the result of the merge like this
(set! layer (car (gimp-image-merge-visible-layers Image 0)))


Oh yeah python (in my opinion is much easier).

_________________
T.
Image gimplearn.net                                                                           


Top
 Post subject: Re: Script to save already open png file and exit
PostPosted: Sat Oct 07, 2017 9:55 am  (#9) 
Offline
GimpChat Member

Joined: Oct 06, 2017
Posts: 6
@trandoductin That worked. Thank you


Top
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) solved] How to mimic File > Open as Layers from within a python script

5

No new posts "Open" SVG file vs "Open as Layers" SVG file [Answered]

5

No new posts File -> Save All

8

No new posts Attachment(s) Unable to open, save, and export

1

No new posts *Save As* File Types

6



* Login  



Powered by phpBB3 © phpBB Group