11-07-2015, 07:55 PM | #1 |
Guru
Posts: 825
Karma: 2525050
Join Date: Jun 2010
Device: K3W, PW4
|
plugin to paste an image file from clipboard
I believe an edit plugin could be created to retrieve an image from the clipboard and save it in the epub Images. I lack knowledge in Python, the interfaces to the clipboard and the tools to work with the epub from the plugin, so I am hoping that someone else might be interested in creating such a plugin.
The incentive for this plugin is to make it simpler to incorporate images that are not already stored on the computer, typically from the internet, into the epub being edited by Sigil. The current method of incorporating such images involves saving them to a file, incorporating that file into the epub and deleting the no longer needed file. Copying the image to the clipboard and then using the plugin to incorporate it into the epub simplifies this greatly. Dave |
11-13-2015, 07:47 AM | #2 |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
[Plugin] PasteImage - Adds images from the clipboard
Updated: December 22, 2015 Current Version: "0.2.1" This is a very simple image pasting plugin that'll add clipboard images to the currently loaded epub as .jpg images (regardless of the original format). Installation: Select Plugins > Manage Plugins > Add Plugin > PasteImage.zip If you're using the Windows version of Sigil 0.9.0 (or higher) select Use Bundled Python. If you're using an older Sigil version, you'll need to install a Python interpreter and the Pillow package. To install Pillow open an admin command prompt and enter the following command: Code:
pip install Pillow Unfortunately, the plugin is not fully compatible with OSX. You can't copy images via the system clipboard, however, you can copy images via browser image URLs. (Right-click the image in the browser and select Copy Image Location/URL.) Usage: Copy an image or an image URL to the clipboard and select Plugins > Edit > PasteImage. Known issues: The plugin won't work with all apps. For example, you can't paste images copied from Google Chrome (Firefox works). You also might get a "Pillow import error" message even though Pillow is installed, if Pillow can't handle the image. The jpeg image quality is hard-coded, but it can easily be changed by editing the quality value in plugin.py. License: GNU General Public License v3 (GPL-3) Last edited by Doitsu; 08-16-2017 at 03:11 AM. Reason: New version with autostart enabled (Sigil 0.9.3+ required) |
Advert | |
|
11-13-2015, 09:28 AM | #3 |
Guru
Posts: 825
Karma: 2525050
Join Date: Jun 2010
Device: K3W, PW4
|
I just installed and tested this on my system, Linux Mint 17.1 rebecca x64 Cinnamon, and tested it with an image from SeaMonkey 2.39 and it worked as designed. Thank you for a quick response to my request for assistance.
Dave |
11-13-2015, 01:03 PM | #4 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Doitsu -- for python2+3 you can use:
Code:
from gi.repository import Gtk, Gdk clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) image = cb.wait_for_text() Last edited by eschwartz; 11-13-2015 at 01:11 PM. |
11-13-2015, 01:07 PM | #5 |
Guru
Posts: 825
Karma: 2525050
Join Date: Jun 2010
Device: K3W, PW4
|
Now that I have tried it on a few real examples I have run into one minor thing I needed to fix in the plugin.py:
On line 41 there is a "png" that should be "jpeg" Once I fixed that I am no longer getting validation errors. Dave |
Advert | |
|
11-13-2015, 01:17 PM | #6 |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
|
11-13-2015, 02:03 PM | #7 | |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
import tempfile from gi.repository import Gtk, Gdk clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) img = clipboard.wait_for_image() if img: temp_file = tempfile.NamedTemporaryFile().name img.save(temp_file, 'jpeg') Code:
AttributeError: 'Pixbuf' object has no attribute 'save' Error: 'Pixbuf' object has no attribute 'save' |
|
11-13-2015, 02:16 PM | #8 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
What lunacy.
Apparently the documentation is wrong, and you should use Code:
img.savev(filename, image_type, ['quality'], ['100']) Last edited by eschwartz; 11-13-2015 at 02:23 PM. |
11-14-2015, 08:13 AM | #9 | |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
I've attached a new version to the second post. Windows users won't need to download this updated version, because it fixes a Linux-only issue. |
|
11-14-2015, 11:25 PM | #10 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Any particular reason you use different methods for PY2 (pygtk) vs PY3 (gi.repository)? Just curious. |
11-15-2015, 01:40 AM | #11 | |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Also, IMHO, the additional if-then import statements make this plugin look more sophisticated. |
|
11-15-2015, 01:53 AM | #12 |
Ex-Helpdesk Junkie
Posts: 19,422
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
|
Sophistication.
|
11-21-2015, 12:26 AM | #13 |
Grand Sorcerer
Posts: 5,582
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
I've added partial OSX support to the plugin. The new version (attached to the second post) allows you to copy web browser images via the image URL. Simply right-click an image in your web browser, select Copy Image Location/URL and then select Plugins > Edit > PasteImage.
Of course, this feature also works with the Windows and Linux versions of Sigil. |
11-21-2015, 06:56 PM | #14 |
Sigil Developer
Posts: 7,506
Karma: 5433350
Join Date: Nov 2009
Device: many
|
Added this to Sigil Plugin Index sticky
|
11-28-2015, 11:10 AM | #15 |
Connoisseur
Posts: 56
Karma: 70350
Join Date: May 2013
Device: Kobo AuraH2O, Glo, AuraHD, JBC2
|
Thanks for the cool plugin. I have a feature request. I would like the ability to paste the image from clipboard to where I have positioned the cursor. Not sure if that is possible.
SH |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[GUI Plugin] Clipboard Search | kiwidude | Plugins | 24 | 03-16-2024 11:06 PM |
new feature request - paste image support | dhdurgee | Sigil | 16 | 11-22-2015 06:29 AM |
Troubleshooting Paste wifi password into text file? | garyyoung | Amazon Kindle | 9 | 07-08-2014 12:15 AM |
How do I copy and paste an image into the body? | Gregg Bell | Feedback | 26 | 02-06-2013 10:42 PM |
copy and paste with image pdf | kab | enTourage Archive | 12 | 04-27-2010 02:32 PM |