On Sat, Jan 2, 2010 at 11:50 AM, Fab <for...@gimpusers.com> wrote:
> I am new to gimp's scripting and would like to automate the rectangle
> selection tool by defining the position and size using a script.
> Afterwards, I would like to extract the selection, 'paste as new image' and
> save the image as a png file without compression.
> It would be nice, if you can give me some hints, how to achieve this. Maybe,
> something similar exists already!?
I've attached some code here - it's from a similar plug-in that I
modified to (almost) do what you want. It will need some work for it
to be useful, but it should be pretty easy to follow and also modify
to suit your needs. I've only given it the barest amount of testing
with gimp 2.6.6 on linux, but it should be cross-platform in theory
(as long as Python+GIMP is correctly installed).
Note that the gimp.file_png_save() call is most likely using
compression - check the procedure browser for the right parameters.
Also, I chose to duplicate/crop/save/destroy rather than
select/copy/paste new/save/destroy - I just found that method simpler.
Hope this helps and good luck!
# Author: Chris Mohler
# Copyright 2009 Chris Mohler
# License: GPL v3
# Version 0.1
# GIMP plugin to export portion of image as PNG
from gimpfu import *
gettext.install("gimp20-python", gimp.locale_directory, unicode=True)
# size and position of rectangle
areaWidth = 200
areaHeight = 200
areaPosX = 20
areaPosY = 20
def export_rect(img, drw, path):
filename = img.name + "-sm.png"
fullpath = os.path.join(path, filename);
tmp = img.duplicate()
pdb.gimp_image_crop(tmp, areaWidth, areaHeight, areaPosX, areaPosY)
pdb.file_png_save(tmp, tmp.layers, fullpath, filename, 0, 9, 1, 1, 1, 1, 1)
blurb=("Export Rectangle as PNG"),
help=("Export Rectangle as PNG."),
(PF_IMAGE, "img", "Image", None),
(PF_DRAWABLE, "drw", "Drawable", None),
(PF_DIRNAME, "path", "Save PNG here", os.getcwd()),
Gimp-user mailing list