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, 10:10 (This post was last modified: Apr 1, 2014 10:11 by bulevardi.)
Post: #2
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, 20:29 (This post was last modified: Apr 1, 2014 20:31 by bulevardi.)
Post: #3
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: #4
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
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Problems with a bat script :( ThaUnknown_ 1 319 Mar 26, 2018 21:14
Last Post: paynekj
  Script-fu ordered file list vnicent 1 167 Mar 19, 2018 17:33
Last Post: paynekj
  script-fu argument/parameter formats dhugg 2 267 Mar 13, 2018 00:50
Last Post: dhugg
  Request for script chlebna 1 441 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 498 Sep 4, 2017 08:51
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS