Hi,
I am working on a project of digitisation of documents in an archive. I am a beginner, I failed in an attempt to code a script to automate the process of cropping and saving an image file with Gimp --leaving a margin around the document image.
In other words, the desired automation would be, step by step:
1. Create a rectangular selection around the document image following the previously established guides.
2. Increase this initial selection in x number of pixels to leave a margin around the document. I achieved to code an easy script for this particular task (in its code you can modify the margin changing the value 50 on the command
steps). I copy the code of this script below this message.
3. Crop the selection.
4. Export the obtained image as a TIFF file format without any compression. Overwrite the existing file.
Many thanks for any help.
**margins.py**#!/usr/bin/env python
from gimpfu import *
def margins(image, drawable):
#Inici de grup de funcions
pdb.gimp_image_undo_group_start(image)
#Afegeix-hi un marge de 0.6 cm, i.e. 71 pixels si dpi=300
steps = 50
pdb.gimp_selection_grow(image, steps)
#Costats no arrodonits
value = 0.0
toggle = 0
pdb.script_fu_selection_rounded_rectangle(image, drawable, value, toggle)
#Final de grup de funcions
pdb.gimp_image_undo_group_end(image)
register(
"python-fu-margins",
"Afegeix un marge a tot el volt de la imatge",
"Afegeix-hi un marge en pixels al comandament steps",
"", "", "2021",
"Margins",
"*",
[
(PF_IMAGE, "image", "takes current image", None),
(PF_DRAWABLE, "drawable", "Input layer", None)
],
[],
margins, menu="<Image>/Select")
main()