Gimp-Forum.net
Noob needs a hand... - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Noob needs a hand... (/Thread-Noob-needs-a-hand)



Noob needs a hand... - vndep - 06-21-2019

Hi, All,

Noob here.  I am trying to write a very simple GIMP-python script; all I want to do is:

(a) starting with a clean background
(b) read a .jpg file from my disk into an image object (e.g., a blue sky with clouds)
© have the image appear on top of the background
(d) write some text in black on top of the image (e.g., "Sample Text")
(e) save the whole thing as a new .png file somewhere on my disk.

I am almost all the way there; I am getting an error when I save (noted below) using this line:     
pdb.gimp_file_save(1, new_img, layer, outputpath, 'AAA_TEST.png')


Thanks in advance!  All help is welcome!

CODE FOLLOWS:


def python_sample_scriptC(image, layer) : #FUNCTION DEFINITION
    pdb.gimp_image_undo_group_start(image)
    pdb.gimp_context_push()

    imagepath = 'G:/Users/Star/Dropbox/Projects/Stock photos/blue-clouds-day-53594.jpg'
    outputpath = 'G:/Users/Star/Dropbox/Projects/Stock photos/AAA_TEST.png'
    text = 'SAMPLE TEXT'
    drawableFLAG = None
    xval = 10
    yval = 10
    borderval = 0
    antialiasFLAG = FALSE
    sizeval = 100
    sizetypeval = 1
    fontnameval = 'Arial Heavy'

    pdb.gimp_message('LOAD IMAGE')
    imageobj = pdb.file_jpeg_load(imagepath, imagepath)
    pdb.gimp_display_new(imageobj)
    pdb.gimp_message('CREATE TEXT LAYER')
    textlayerval = pdb.gimp_text_fontname(imageobj, drawableFLAG, xval, yval, text, borderval, antialiasFLAG, sizeval, sizetypeval, fontnameval)
    pdb.gimp_message('SET TEXT COLOR')
    pdb.gimp_text_layer_set_color(textlayerval, '#ff0000')
    time.sleep(1)
    pdb.gimp_message('DUPLICATE')
    new_image = pdb.gimp_image_duplicate(imageobj)
    pdb.gimp_message('MERGE')
    layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE)
    pdb.gimp_message('SAVE')

# THE CODE FAILS ON THE NEXT LINE
    pdb.gimp_file_save(1, new_img, layer, outputpath, 'AAA_TEST.png')

    pdb.gimp_context_pop()
    pdb.gimp_image_undo_group_end(image)
    pdb.gimp_displays_flush()
    #return


RE: Noob needs a hand... - tmanni - 06-22-2019

You don't need to provide the "run-mode" parameter ; and the variable for your new image is 'new_image', no 'new_img'.
So, replace

Quote:pdb.gimp_file_save(1, new_img, layer, outputpath, 'AAA_TEST.png')

by

Quote:pdb.gimp_file_save(new_image, layer, outputpath, 'AAA_TEST.png')



RE: Noob needs a hand... - vndep - 06-22-2019

(06-22-2019, 05:15 AM)tmanni Wrote: You don't need to provide the "run-mode" parameter ; and the variable for your new image is 'new_image', no 'new_img'.
So, replace

Quote:pdb.gimp_file_save(1, new_img, layer, outputpath, 'AAA_TEST.png')

by

Quote:pdb.gimp_file_save(new_image, layer, outputpath, 'AAA_TEST.png')

Thanks!