#!/usr/bin/env python # -*- coding: utf8 -*- # # Copyright (C) 2014 Niccolo Rigacci # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # To assign a keyboard shortcut in GIMP: menu Edit, Preferences, # Interface, Configure Keyboard Shortcuts, Search "Export selection", # assign a keyboard combination, e.g. Ctrl-Alt-E. # Then click on Save Keyboard Shortcuts Now from gimpfu import * import os, sys def rotate_and_export_jpeg(img, drawable, image_number, rotate): pdb.gimp_edit_copy(drawable) tmp_image = pdb.gimp_edit_paste_as_new() if rotate == 1: pdb.gimp_image_rotate(tmp_image, ROTATE_90) if rotate == 2: pdb.gimp_image_rotate(tmp_image, ROTATE_180) if rotate == 3: pdb.gimp_image_rotate(tmp_image, ROTATE_270) tmp_layer = pdb.gimp_image_get_active_layer(tmp_image) tmp_display = pdb.gimp_display_new(tmp_image) # Make unique filename. filename = "%02d" % (image_number) minor_number = 0 while os.path.exists(filename + ".jpg"): filename = "%02d-%03d" % (image_number, minor_number) minor_number += 1 pdb.file_jpeg_save( tmp_image, tmp_layer, filename + ".jpg", # filename filename, # raw-filename 0.92, # quality 0.00, # smoothing 1, # optimize 0, # progressive "", # comment 0, # subsampling option number 1, # force baseline jpeg 0, # interval of restart markers 2 # dct algorithm to use ) pdb.gimp_display_delete(tmp_display) register( "export-selection", "Export selections as jpeg image, with rotation", "Export selections as jpeg image, with rotation", "Niccolo Rigacci ", "Niccolo Rigacci - GPL v.3", "2014-04-22", "/Tools/Selection Tools/Export selection as jpeg...", "*", [ (PF_SPINNER, "image_number", "Image number: ", 0, (0, 100, 1)), (PF_OPTION, "rotate", "Rotate clockwise: ", 0, ("No", "90", "180", "270")) ], [], rotate_and_export_jpeg ) main()