MobileRead Forums

MobileRead Forums (https://www.mobileread.com/forums/index.php)
-   Plugins (https://www.mobileread.com/forums/forumdisplay.php?f=268)
-   -   Wrap in SVG plugin? (https://www.mobileread.com/forums/showthread.php?t=255300)

gezginrocker 02-01-2015 02:50 AM

Wrap in SVG plugin?
 
Hi,

Currently I'm using "Add Cover" tool to wrap my images in SVG. But it is quite a work doing all images one by one. It would be very nice if there was a plugin which allows us to right click an image and choose option "Wrap in SVG", as discussed here: https://www.mobileread.com/forums/arc.../t-215664.html

Thanks

Toxaris 02-01-2015 04:11 AM

I am actually thinking about that, but I think that the plugin system is not fit for that.

user_none 02-01-2015 10:01 AM

Quote:

Originally Posted by Toxaris (Post 3037436)
I am actually thinking about that, but I think that the plugin system is not fit for that.

The plugin system as designed would not work for this situation. It was designed with separation from the GUI from the get go in mind. This way 1) Plugins are not tied specifically to Sigil (some plugins are dual calibre and sigil plugins for example). 2) Licensing, by having an API and separation plugin authors can choose any license (even commercial) for their plugins.

These choices do limit what plugins can do. But something like this might not be a bad idea for including as part of Sigil itself.

My gut feeling (not really having looking into this much) is a clip that uses a regex to wrap an image in SVG would be the best way to go. It might be a good example clip for us to add.

Toxaris 02-01-2015 11:07 AM

Quote:

Originally Posted by user_none (Post 3037601)
The plugin system as designed would not work for this situation. It was designed with separation from the GUI from the get go in mind. This way 1) Plugins are not tied specifically to Sigil (some plugins are dual calibre and sigil plugins for example). 2) Licensing, by having an API and separation plugin authors can choose any license (even commercial) for their plugins.

These choices do limit what plugins can do. But something like this might not be a bad idea for including as part of Sigil itself.

My gut feeling (not really having looking into this much) is a clip that uses a regex to wrap an image in SVG would be the best way to go. It might be a good example clip for us to add.

That is what I thought.

The issue with a regex or clip, is that the dimensions of the image must be adjusted based on the actual image. That cannot be retrieved by a regex or clip.

user_none 02-01-2015 11:09 AM

Quote:

Originally Posted by Toxaris (Post 3037644)
That is what I thought.

The issue with a regex or clip, is that the dimensions of the image must be adjusted based on the actual image. That cannot be retrieved by a regex or clip.

You are correct, the actual dimensions cannot be pulled but most of the time I've noticed people use a set dimension for SVG images because they use a high quality image and want it scaled down. So in that sense a clip would work.

* SVG wrapped images I should say

theducks 02-01-2015 11:24 AM

Quote:

Originally Posted by gezginrocker (Post 3037412)
Hi,

Currently I'm using "Add Cover" tool to wrap my images in SVG. But it is quite a work doing all images one by one. It would be very nice if there was a plugin which allows us to right click an image and choose option "Wrap in SVG", as discussed here: https://www.mobileread.com/forums/arc.../t-215664.html

Thanks

+1
I currently 'walk' a cover leaving behind SVG wrapped IMG code. It is tedious deleting the 2 symantics so I could do the next cover

:bulb2: Maybe a change to "Tools:Add Cover' to Tools:Wrap SVG which has a tick Make this the Cover (which does the current 3 additional steps:1) moves from current filelist insert location to first file, 2)IMG semantic set to 'cover', 3)file semantic set to 'cover'

KevinH 02-01-2015 11:51 AM

Hi,

Actually, you could do something like this in a plugin as well. You just could not tie it to the right click menu. Instead you would invoke an SVGImgWrapper edit plugin which pop up a gui list of all of the images it finds in the book, and you simply check which ones (or all) you want to wrap. It would then walk all of the html files and applying the wrapping where needed. Not as nice as your right click approach but doable I think, unless I am missing something.

KevinH

gezginrocker 02-04-2015 07:13 AM

I agree, it doesn't have to be right click. Just some less hassle way to wrap images in SVG.

AlanHK 04-10-2015 04:04 AM

Quote:

Originally Posted by theducks (Post 3037651)
+1
I currently 'walk' a cover leaving behind SVG wrapped IMG code. It is tedious deleting the 2 symantics so I could do the next cover

:bulb2: Maybe a change to "Tools:Add Cover' to Tools:Wrap SVG which has a tick Make this the Cover (which does the current 3 additional steps:1) moves from current filelist insert location to first file, 2)IMG semantic set to 'cover', 3)file semantic set to 'cover'

Yes, just expanding the functionality a little.
Or, adding it as an option under "Insert": "insert image as SVG".
In fact, "Add a a cover" would also be better under that head than the grab-bag "Tools" heading.

For a while I was adding full-page images by "adding a cover" and then found it overwrote the "real" cover file and tagged the new image as the cover. (I wasn't aware of the semantic tags until then.)

So it ended up being less hassle to just do it by hand than clean up the mess.

KevinH 04-10-2015 12:40 PM

Hi,

If you want this feature any time soon, I would suggest a python plugin. If you can show me the before and after html, I can create a plugin that will wrap all images with the desired svg code and not have it add a cover semantics.

KevinH

Doitsu 04-18-2015 11:21 AM

2 Attachment(s)
rubeus has developed a more advanced version that you can download here. Please download his version unless you're using an older Sigil version and/or Python 2.7.x.

With the help of KevinH, who gave me some extremely helpful pointers, I've created a very simple proof-of-concept plugin that duplicates the functionality of Tools > Add Cover but doesn't touch the existing cover or the guide section.

Usage:

1. Install the plugin as usual.
2. Select Plugins > Edit > SVGWrapper > Start.
3. Click the arrow of the dropdown box, select an image and click Insert.
4. Repeat step 3 until you've added all the desired images.
5. Click Done to close the Insert Image dialog box and OK to close the Plugin Runner dialog box.

Known issues:

1. The Book Browser won't be updated if you click the Insert button, but the plugin will write a xxx.xhtml added message to the Plugin Runner window. (The Book Browser will be updated when you click Done.)
2. You can't select the location or the name of added images. (Each image will be added at the beginning of the book using the image name as the file name.)

Credits:

This plugin uses code originally developed by the KindleUnpack developers.

DiapDealer 04-18-2015 11:54 AM

Cool! Good work.

I know it was probably easiest when re-using the KindleUnpack code, but keep in mind that most of the functions provided by utf8_utils.py and path.py are already available in the plugin framework via "compatibility_utils.py" and "unipath.py" respectively.

No need to root them out and change them in this case since they just work, but something to keep in mind for the future. :)

KevinH 04-18-2015 01:04 PM

Hi Doitsu,
Nicely done!

As DiapDealer mentioned, if it would make things easier you might want to simply copy the get_image_size routine out of mobi_cover.py and paste it as a routine in your plugin.py and then remove all of the utf8utils, path.py, and mobi_cover.py so you don't have to keep those pieces around.

KindleUnpack (we) found that particular routine online in gpl, lgpl, and bsd versions so if you extract it you can pretty much claim any license you want for your code since you would not need anything else from KindleUnpack.

Thanks so much for your plugin! I will add it to the sticky list of plugins unless DiapDealer beats me to it!

KevinH

KevinH 04-18-2015 01:55 PM

Hi All,

I have added Doitsu's latest plugin and my SanityChecker to the Sigil Plugin Index and cleaned it up a bit and added the short description from the plugin.xml for each.

Please let me know if anyone else has posted plugins that need to be added to the Sigil plugin index.

Thanks!

KevinH

Doitsu 04-18-2015 02:10 PM

Quote:

Originally Posted by KevinH (Post 3085817)
As DiapDealer mentioned, if it would make things easier you might want to simply copy the get_image_size routine out of mobi_cover.py and paste it as a routine in your plugin.py.

I originally tried to use the mobi_cover.py version that you recommended but I had problems with missing imports and decided to simply use the KindleUnpack version. After all, it's more or less a throwaway plugin that doesn't really do much.

Quote:

Originally Posted by KevinH (Post 3085817)
KindleUnpack (we) found that particular routine online in gpl, lgpl, and bsd versions so if you extract it you can pretty much claim any license you want for your code since you would not need anything else from KindleUnpack.

However, without KindleUnpack (and your help) I wouldn't have found that routine. IMHO, it's only fair to mention that the most sophisticated part of the plugin code wasn't written by me. :)

DiapDealer 04-18-2015 03:20 PM

Quote:

Originally Posted by Doitsu (Post 3085852)
IMHO, it's only fair to mention that the most sophisticated part of the plugin code wasn't written by me. :)

Well, if sophistication is the bar being set, I'm pretty sure I haven't written much Python code at all. :D

rubeus 07-04-2015 04:17 PM

Is there a way to have the dropdown box showing sorted img-keys?

Ok that was easy :)

replace
Code:

        image['values'] = img_dic.keys()
with
Code:

        image['values'] = sorted(img_dic.keys())
Why is

Code:

        image['values'] = img_dic.keys().sort()
exporting an empty list?

DiapDealer 07-04-2015 05:37 PM

Quote:

Originally Posted by rubeus (Post 3128652)
Why is

Code:

        image['values'] = img_dic.keys().sort()
exporting an empty list?

The sort() method of a list modifies the list in place, but returns None. To do what you want with the list method, you'd have to do something like:

Code:

image['values'] = img_dic.keys()
image['values'].sort()
print image['values']

The 'sort' list method was all that was available prior to Python 2.4. The builtin function 'sorted' (available from Python 2.4+) builds a new sorted list from any iterable--and is imminently handier most times--as you've no doubt discovered. ;)

Code:

print sorted(img_dic.keys())

rubeus 07-05-2015 01:20 AM

Quote:

Originally Posted by DiapDealer (Post 3128681)
The sort() method of a list modifies the list in place, but returns None.

:smack:

:thanks:


All times are GMT -4. The time now is 08:03 PM.

Powered by: vBulletin
Copyright ©2000 - 3.8.5, Jelsoft Enterprises Ltd.
MobileRead.com is a privately owned, operated and funded community.