Almost done!
One last thing that I cannot figure out is: how do you close the dialog
box that the image is sitting in? In Scheme you do it like so:
(gimp-display-delete Image)
I've tried the following (with variations), but it causes the python-fu
to hang:
pdb.gimp_display_delete(img)
Anyway ... here's the code so far:
#!/usr/bin/env python
# Send to Web - Re-samples an image, adds drop shadow, and saves it
# to ls1 www images directory so that it can be used
# in a 'Top News of the Day' article.
import os
from gimpfu import *
def python_send_to_web(img, drawable, filename):
img.disable_undo()
# local variables:
SRCFilename = "/tmp/" + filename
RemoteDirectory = "ls1:/home/tony/"
SCPProgram = "/usr/bin/scp"
width = img.width
height = img.height
# hack to make the next section work:
blank_layer = gimp.Layer(img, "blank", width, height, RGB_IMAGE, 0,
NORMAL_MODE)
img.add_layer(blank_layer, 0)
gimp.displays_flush()
# merge all the layers for just in case the user has done some editing:
pdb.gimp_image_merge_visible_layers(img, 0)
# screwed up the drawable when I merged the layers:
drawable = pdb.gimp_image_get_active_drawable(img)
# scale the image if it's too big:
if (width > 470):
newheight = ((height * 470) / width)
pdb.gimp_image_scale(img, 470, newheight)
gimp.displays_flush()
# add a drop shadow:
pdb.script_fu_drop_shadow(img, drawable, 8.0, 8.0, 15.0, [0,0,0],
80.0, TRUE)
gimp.displays_flush()
# final layer merge:
pdb.gimp_image_merge_visible_layers(img, 0)
drawable = pdb.gimp_image_get_active_drawable(img)
# save the image in png format to disk:
pdb.file_png_save2(img, drawable, SRCFilename, filename, FALSE, 6,
TRUE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE)
gimp.displays_flush()
# close the python-fu dialog box:
gimp.delete(img)
# send the image to our ls1 directory:
command = SCPProgram + " " + SRCFilename + " " + RemoteDirectory
os.popen(command)
# user needs some feedback:
pdb.gimp_message("Cool! Your picture is online. You may now
include it in a 'Top News of the Day' article.")
# I'd like to be able to close the dialog that the image is sitting
in ...
# but I cannot figure out how to do this. I'll leave it open.
Hopefully the
# user will not be too confused by this.
#pdb.gimp_display_delete(img)
register(
"python_fu_send_to_web",
"Send an image to ls1 rsync directory",
"Send image to ls1 for rsync to web farm after resampling it to
proper size and adding drop shadow.",
"Tony Freeman <[EMAIL PROTECTED]>",
"National Weather Service, Louisville",
"2007",
"<Image>/NWS/Send to web...",
"RGB*, GRAY*",
[
(PF_STRING, "filename", "Filename", "web-image.png"),
],
[],
python_send_to_web)
main()
_______________________________________________
Gimp-user mailing list
[email protected]
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-user