Last active
September 25, 2020 18:53
-
-
Save pradishb/99ad68c198e3962cc660acda53bf30da to your computer and use it in GitHub Desktop.
Gimp python plugin to copy rectangle (x, y, w, h) to clipboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os | |
import platform | |
import subprocess | |
from gimpfu import * | |
def get_rectangle(image): | |
selection, x_1, y_1, x_2, y_2 = pdb.gimp_selection_bounds(image) | |
rectangle = x_1, y_1, x_2-x_1, y_2-y_1 | |
if not selection: | |
gimp.message("No selection") | |
else: | |
file_path = os.path.expanduser('~/rectangle.txt') | |
with open(file_path, 'w') as file_pointer: | |
file_pointer.write(str(rectangle)) | |
try: | |
if platform.system() == 'Windows': | |
with open(file_path) as file_pointer: | |
subprocess.call('clip', stdin=file_pointer) | |
else: | |
subprocess.call([ | |
'xclip', | |
'-sel', | |
'clip', | |
file_path, | |
]) | |
except Exception: | |
pass | |
gimp.message('Output: ' + str(rectangle)) | |
register( | |
"gimp_get_selection_rectangle", | |
"Get selection rectangle", | |
"Get selection rectangle", | |
"Pradish Bijukchhe", | |
"Pradish Bijukchhe", | |
"2020", | |
"Get selection rectangle (x, y, w, h)", | |
"", | |
[ | |
(PF_IMAGE, "image", "Input image", None), | |
], | |
[], | |
get_rectangle, menu="<Image>/Edit") | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment