Post Reply 

resize and add layer script

Apr 1, 2014, 09:07 (This post was last modified: Apr 1, 2014 09:08 by bulevardi.)
Post: #1
resize and add layer script
Hi all,

I'm currently new to The Gimp.
Just abandoned photoshop few weeks ago and starting to get my macros done in Gimp.
I chose for Python, but I want to try Scheme aswel if that's easier. I'm new to both.

It's not working, I probably made some major errors in the syntax, first of all, the menu is not even showing.

I need something that:
- checks wether the photo is horizontal/vertical/square
- resizes to a max length specified in the script
- opens image as layer on top, to add an image containing a border
- saves as jpg max quality + add '-border' in the name

Can someone help? Wether Python or Scheme...
I'm currently running GIMP in Windows, later on I'll use this in Linux too. But do I have to install Python separately? Maybe Scheme is easier?

I'm that far already:


Code:
#!/usr/bin/python

from gimpfu import *


def plugin_main(myImage, drawable):
    

    currentWidth = drawable.width
    currentHeight = drawable.height
    
     #check if it's a horizontal/vertical/square photo:

    if (currentWith > currentHeight):
    
    pdb.gimp_image_scale_full(myImage, 800, 533, INTERPOLATION_NONE)
    pdb.gimp_file_load_layer("/../horizontal.psd")

    elsif (currentWith < currentHeight):

    pdb.gimp_image_scale_full(myImage, 533, 800, INTERPOLATION_NONE)
    pdb.gimp_file_load_layer("/../vertical.psd")

    elsif (currentWith = currentHeight):

    pdb.gimp_image_scale_full(myImage, 532, 532, INTERPOLATION_NONE)
    pdb.gimp_file_load_layer("/../square.psd")

     # save


      pdb.file_jpeg_save(myImage, drawable, myImage.name+"-border.jpg", myImage.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0)


register(
        "python_fu_myscript",
        "Saves the image with border",
        "Saves the image with border",
        "Dirk Desmet",
        "Dirk Desmet",
        "2014",
        "<Image>/MyScripts/addborder",
        "*, *",
        [],
        [],
        plugin_main)

main()

Thanks in advance!
Find all posts by this user
Quote this message in a reply
Apr 1, 2014, 09:47 (This post was last modified: Apr 1, 2014 09:48 by paynekj.)
Post: #2
RE: resize and add layer script
You have a number of Python errors in your code:

In Python indentation is significant.

elsif is not a key-word, you should use elif

You can't do assignments (=) in if/elif tests, you must use the test for equality instead (==)

So I got the following to register in the menus (I haven't checked if it actually works):
Code:
#!/usr/bin/python

from gimpfu import *


def plugin_main(myImage, drawable):
    

    currentWidth = drawable.width
    currentHeight = drawable.height
    
     #check if it's a horizontal/vertical/square photo:

    if (currentWith > currentHeight):
    
      pdb.gimp_image_scale_full(myImage, 800, 533, INTERPOLATION_NONE)
      pdb.gimp_file_load_layer("/../horizontal.psd")

    elif (currentWith < currentHeight):

      pdb.gimp_image_scale_full(myImage, 533, 800, INTERPOLATION_NONE)
      pdb.gimp_file_load_layer("/../vertical.psd")

    elif (currentWith == currentHeight):

      pdb.gimp_image_scale_full(myImage, 532, 532, INTERPOLATION_NONE)
      pdb.gimp_file_load_layer("/../square.psd")

     # save


    pdb.file_jpeg_save(myImage, drawable, myImage.name+"-border.jpg", myImage.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0)


register(
        "python_fu_myscript",
        "Saves the image with border",
        "Saves the image with border",
        "Dirk Desmet",
        "Dirk Desmet",
        "2014",
        "<Image>/MyScripts/addborder",
        "*, *",
        [],
        [],
        plugin_main)

main()

Kevin
Find all posts by this user
Quote this message in a reply
Apr 1, 2014, 10:10 (This post was last modified: Apr 1, 2014 10:11 by bulevardi.)
Post: #3
RE: resize and add layer script
(Apr 1, 2014 09:47)paynekj Wrote:  elsif is not a key-word, you should use elif

Woah, thanks for the quick reply!

I saw in a tutorial before the "elif" keyword, and thought that it was a typo Big Grin But it really is elif Big Grin
Ok, got it Smile

Going to test this tonight on the computer where I have gimp installed. I'll let you know if it works Smile

I'm wondering if all parameters are needed in the save function for example:
pdb.file_jpeg_save(myImage, drawable, myImage.name+"-border.jpg", myImage.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0)

And the INTERPOLATION_NONE in the image scale function won't be necessary I presume...

Thanks anyhow Smile
Find all posts by this user
Quote this message in a reply
Apr 1, 2014, 10:19
Post: #4
RE: resize and add layer script
(Apr 1, 2014 10:10)bulevardi Wrote:  I'm wondering if all parameters are needed in the save function for example:
pdb.file_jpeg_save(myImage, drawable, myImage.name+"-border.jpg", myImage.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0)

And the INTERPOLATION_NONE in the image scale function won't be necessary I presume...

All the parameters are required and so must be present. GIMP functions don't have default values for parameters and they must be supplied.

Kevin
Find all posts by this user
Quote this message in a reply
Apr 1, 2014, 20:29 (This post was last modified: Apr 1, 2014 20:31 by bulevardi.)
Post: #5
RE: resize and add layer script
He's still not doing it.

I made the plugin selectable in the menu already.
But than when clicking, it does not do anything.

Tried to change lots of things ... but when testing in the console, he's giving me indentation problems, while they should've been resolved.

Quote:#!/usr/bin/env python

from gimpfu import *



def plugin_main(my_image, drawable):
currentWidth = my_image.width
currentHeight = my_image.height


#check if it's a horizontal/vertical/square photo:

if (currentWith > currentHeight):

pdb.gimp_image_scale_full(my_image, 800, 533, INTERPOLATION_NONE)
pdb.gimp_file_load_layer("D:\Fotos\Border Flickr 800x532 Horizontaal.psd")

elif (currentWith < currentHeight):

pdb.gimp_image_scale_full(my_image, 533, 800, INTERPOLATION_NONE)
pdb.gimp_file_load_layer("D:\Fotos\Border Flickr 800x532 Vertikaal.psd")

elif (currentWith == currentHeight):

pdb.gimp_image_scale_full(my_image, 532, 532, INTERPOLATION_NONE)
pdb.gimp_file_load_layer("D:\Fotos\Border Flickr 800x532 Square.psd")

# save


pdb.file_jpeg_save(my_image, drawable, my_image.name+"-border.jpg", my_image.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0)


register(
"Flickr",
"Saves the image with border",
"Saves the image with border",
"Dirk Desmet",
"Dirk Desmet",
"2014",
"<Image>/MyScripts/Test",
"*",
[],
[],
plugin_main,
)

main()

Perhaps I should try Scheme instead.
Find all posts by this user
Quote this message in a reply
Apr 1, 2014, 21:47
Post: #6
RE: resize and add layer script
In Scheme, it's working as it should !

Quote:(define (Flickr-Hori image drawable)
(let*(
(back-layer 0)
)

(gimp-image-scale image 800 533)

(set! back-layer(car (gimp-file-load-layer RUN-NONINTERACTIVE image "D:/Fotos/hori.png")))

(gimp-image-insert-layer image back-layer -1 0)
(gimp-displays-flush)

(file_jpeg_save(1, image, drawable, image.name+"-border.jpg", image.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0))

)
)

Only the file save as jpg line is n't working
Find all posts by this user
Quote this message in a reply
Apr 2, 2014, 06:01
Post: #7
RE: resize and add layer script
(Apr 1, 2014 21:47)bulevardi Wrote:  In Scheme, it's working as it should !

Quote:(define (Flickr-Hori image drawable)
(let*(
(back-layer 0)
)

(gimp-image-scale image 800 533)

(set! back-layer(car (gimp-file-load-layer RUN-NONINTERACTIVE image "D:/Fotos/hori.png")))

(gimp-image-insert-layer image back-layer -1 0)
(gimp-displays-flush)

(file_jpeg_save(1, image, drawable, image.name+"-border.jpg", image.name+"-border.jpg", 1, 0, 0, 0, "", 0, 0, 0, 0))

)
)

Only the file save as jpg line is n't working

You have to use string-append to join strings together not +

Kevin
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for script chlebna 1 235 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 296 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 1 334 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 260 Aug 23, 2017 12:48
Last Post: paynekj
  Need help in running a gui script-fu via command line eyalzek 2 418 Oct 4, 2014 14:05
Last Post: eyalzek

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS