I've recently taken to creating imges and sharing them. It's quite fun to be able to put things straight on the clipboard and share them rather than having to mess with files. Some tools like, Spectacle have features for this and I've hacked up my own using ffmpeg -f x11grab when they don't exist xclip -i -t image/png. Now I'm dabbling with a little image editing with GIMP.
What I would ideally like to do would me to export an image directly from GIMP to the clipboard - but I could work out a way to do this. I would just take a screenshot but there is a dashed line around the image.
Copying layers with Ctrl + C seems to work so one work around is to flatten copy the layers and undo. Also there is gimp-console, so I could probably do anything I want with that - but it feels a bit like using powertools to hang a poster.
Progress
I found this Stack Overflow answer.
It looks like script-fu has no access to the clipboard. It can however export to files. I got this far with script-fu and the approach would work using gimp --batch to run the script. But the number of arguments I need to specify for file-png-save put me off. I wonder if pythonfu has default parameters.
(if (not (= (vector-length (cadr (gimp-image-list))) 1)) (error "More than one image"))
(define image (vector-ref (cadr (gimp-image-list)) 0))
(define copied-image (car (gimp-image-duplicate image)))
(define flat-layer (gimp-image-flatten copied-image))
(file-png-save...)
Pythonfu
I switched to Pythonfu. Unforunately, pythonfu was missing from GIMP. I fixed this by switching to GIMP 3's AppImage - I needed to change the theme to the system default for the fonts in the Python console to be readable.
The following snippet works from the pythonfu console:
image, = Gimp.get_images()
copy = image.duplicate()
copy.flatten()
Gimp.file_save(Gimp.RunMode.NONINTERACTIVE, copy, Gio.File.new_for_path(str(Path.home() / "tmp" / "gimp_clip.png")))
subprocess.check_call(["xclip", "-i", str(path), "-selection", "CLIPBOARD", "-t", "image/png"])
copy.delete()
