Post Reply 

Script Fu to scale and round corners?

Jan 10, 2012, 19:37
Post: #1
Script Fu to scale and round corners?
I'm looking to use script-fu to automate a process I do at work.

What I do is find images, paste them into GIMP, scale them down, and round the corners.

I've been playing around with script fu to make it automatically scale the image and round the corners, but I've run into problems with the image variable needing to be changed each time something is pasted.

Is there a way I can automate this, perhaps some code that will set the image variable to whatever the current window is, or am I stuck doing "manual labor"?
Thanks!
Find all posts by this user
Quote this message in a reply
Jan 10, 2012, 20:18
Post: #2
RE: Script Fu to scale and round corners?
Can you detail exactly what you do to "paste" the image into GIMP as I'm puzzled by your saying that the image variable needs to be changed every time.

Normally scripts are run on the active image, and get passed the image id when the script is called.
Find all posts by this user
Quote this message in a reply
Jan 10, 2012, 20:47
Post: #3
RE: Script Fu to scale and round corners?
I need to make a pizza icon. So I google "pizza" and find an image that looks like it will scale well. I then "Copy Image" from the web and paste into GIMP. What I would then do is scale it, then apply rounded corners. While not too tedious, I'd like it if I could do both with the push of 1 button, as the scale size and rounded corner parameters never change.

What I've made thus far is this little script. The problem is X, which is the image variable. When I put it to 1, it works well the first time. However, after saving an image and closing the active window, then pasting a new image into GIMP, the image ID (?) now becomes 2. This means for me in my script that I have to change the x from 1 to 2. Is there a way I can tell script-fu to look at the image ID of whatever image is currently open?... Does that make more sense?

Here's my little...line of script-fu:
(gimp-image-scale x 104 91)(script-fu-round-corners TRUE x 10 10 FALSE 8 8 15 FALSE FALSE)
Find all posts by this user
Quote this message in a reply
Jan 10, 2012, 21:19 (This post was last modified: Jan 10, 2012 21:19 by paynekj.)
Post: #4
RE: Script Fu to scale and round corners?
Are you typing your "script" into the script-fu console? rather than creating a script file and calling it from a menu?

Here's what I would do - save this code into a file - say mookler.scm in your personal script folder (see Edit>>Preferences>>Folders>>Scripts for your script folders)
Code:
(define (script-fu-mookler image drawable)
  (let* ()
    (gimp-image-scale image 104 91)
    (script-fu-round-corners image drawable 10 FALSE 8 8 15 FALSE FALSE)
  )
)

(script-fu-register "script-fu-mookler"
                    "Mookler's Script"
                    "Script by Mookler"
                    "Copyright (C) 2011 Mookler"
                    "Mookler"
                    "Version 0.1"
                    "RGB*"
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
)

(script-fu-menu-register "script-fu-mookler" "<Image>/Mookler")

Then either re-start GIMP or select Filters>>Script-Fu>>Refresh Scripts

You should then have a "Mookler>>Mookler's Script menu entry
Find all posts by this user
Quote this message in a reply
Jan 10, 2012, 21:30 (This post was last modified: Jan 10, 2012 21:38 by Mookler.)
Post: #5
RE: Script Fu to scale and round corners?
(Jan 10, 2012 21:19)paynekj Wrote:  Are you typing your "script" into the script-fu console? rather than creating a script file and calling it from a menu?

Here's what I would do - save this code into a file - say mookler.scm in your personal script folder (see Edit>>Preferences>>Folders>>Scripts for your script folders)
Code:
(define (script-fu-mookler image drawable)
  (let* ()
    (gimp-image-scale image 104 91)
    (script-fu-round-corners image drawable 10 FALSE 8 8 15 FALSE FALSE)
  )
)

(script-fu-register "script-fu-mookler"
                    "Mookler's Script"
                    "Script by Mookler"
                    "Copyright (C) 2011 Mookler"
                    "Mookler"
                    "Version 0.1"
                    "RGB*"
                    SF-IMAGE "Input Image" 0
                    SF-DRAWABLE "Input Drawable" 0
)

(script-fu-menu-register "script-fu-mookler" "<Image>/Mookler")

Then either re-start GIMP or select Filters>>Script-Fu>>Refresh Scripts

You should then have a "Mookler>>Mookler's Script menu entry

This is going to sound dumb, probably because I have no coding experience, but what I had done in the past was just take that short line I provided and saved it into a .scm. You're script that you provided does exactly what I want it to do...thanks a hundred times over!
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Need help in running a gui script-fu via command line eyalzek 2 223 Oct 4, 2014 14:05
Last Post: eyalzek
  Color menuitems in script or plugin Barbie 4 379 Sep 29, 2014 09:51
Last Post: paynekj
  script-fu ok in gimp, not in commad line dominique 1 260 Sep 28, 2014 03:18
Last Post: dominique
  Script fu and Color to alpha john 4 386 Sep 20, 2014 08:46
Last Post: rich2005
  Setting text markup from python script Burbly 1 286 Sep 16, 2014 12:29
Last Post: Burbly

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS