Put the python script in the GIMP plug-ins folder and restart GIMP
Find which folder that is in Edit / Preferences / Folders / Plug-ins
#!/usr/bin/env python | |
from gimpfu import * | |
from time import time | |
import gtk | |
import collections | |
import os | |
def do_stuff(img, layer, folder, prefix) : | |
filename = "{}/{}-{:.0f}.png".format(folder, prefix, time() * 1000) | |
gimp.progress_init("Exporting to " + filename) | |
new_image = pdb.gimp_image_duplicate(img) | |
layer = pdb.gimp_image_merge_visible_layers(new_image, CLIP_TO_IMAGE) | |
non_empty, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img) | |
pdb.gimp_image_crop(new_image, x2-x1, y2-y1,x1, y1) | |
gimp.progress_update(25) | |
pdb.plug_in_autocrop(new_image, layer) | |
gimp.progress_update(50) | |
pdb.file_png_save_defaults(new_image, layer, filename, filename) | |
gimp.progress_update(75) | |
pdb.gimp_image_delete(new_image) | |
gimp.progress_update(100) | |
register( | |
"extract_content_as_pngfu", | |
"Extract content as PNG...", | |
"Export a PNG of the cropped content of the view/selection", | |
"pho", | |
"pho", | |
"2020", | |
"Extract content as PNG...", | |
"*", | |
[ | |
(PF_IMAGE, "image", "Input image", None), | |
(PF_DRAWABLE, "drawable", "Input layer", None), | |
(PF_DIRNAME, "folder", "Folder to save", ""), | |
(PF_STRING, "prefix", "File prefix", "file") | |
], | |
[], | |
do_stuff, menu="<Image>/Filters/Render") | |
main() |