09-15-2015, 05:19 AM | #46 | |
Grand Sorcerer
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Maybe the problem is caused by a leftover ePubTidyTool.json file. You may want to manually delete the following folders and reinstall the plugin. Code:
%localappdata%\sigil-ebook\sigil\plugins_prefs\ePubTidyTool %localappdata%\sigil-ebook\sigil\plugins\ePubTidyTool |
|
09-15-2015, 05:42 AM | #47 |
Connoisseur
Posts: 81
Karma: 10
Join Date: Nov 2013
Device: Kobo Aura HD
|
It work now. Thanks Doitsu
@CalibUser I add some more fixes Code:
#Fixes '…' when PDFd as ... CorrectText("Changed ... to …", r'\.\.\.', r'…') #Fixes 'η' when PDFd as ΐ] CorrectText("Changed ΐ] to η", r'ΐ]', r'η') #Fixes 'στη' when PDFd as σιη CorrectText("Changed σιη to στη", r'σιη', r'στη') #Fixes 'στ(η|ο|ον|α|ις|ην)' when PDFd as '"οτ(η|ο|ον|α|ις|ην)' CorrectText("Changed οτ(η|ο|ον|α|ις|ην) to στ(η|ο|ον|α|ις|ην)", r' οτ(η|ο|ον|α|ις|ην) ', r' στ\1 ') #Fixes 'των' when PDFd as 'τ(οι|οι)ν' CorrectText("Changed τ(οι|ιο)ν to των", r' τ(οι|ιο)ν ', r' των ') #Fixes 'ού' when PDFd as 'οιί' CorrectText("Changed οιί to ού", r'οιί', r'ού') #Fixes 'στις' when PDFd as σιις CorrectText("Changed σιις to στις", r'σιις', r'στις') #Fixes 'στ(η|ο|ον|ην)' when PDFd as οτ(η|ο|ον|ην) CorrectText("Changed οτ(η|ο|ον|ην) to στ(η|ο|ον|ην)", r' οτ(η|ο|ον|ην) ', r'στ\1') #Fixes 'στ(ο|ου|α)' when PDFd as σι(ο|ου|α) CorrectText("Changed σι(ο|ου|α) to στ(ο|ου|α)", r' σι(ο|ου|α)', r'στ\1') #Fixes 'ώ' when PDFd as ο'ι CorrectText("Changed ο'ι to ώ", r'(ο\'ι|\(ί\))', r'ώ') #Fixes 'Άκουσ' when PDFd as Ακόυσ CorrectText("Changed Ακόυσ to Άκουσ", r'Ακόυσ', r'Άκουσ') #Fixes 'γι’' when PDFd as γΓ,γΡ CorrectText("Changed γΓ γΡ to γι’", r'(γΓ|γΡ)', r'γι’') #Fixes 'ντι' when PDFd as νπ CorrectText("Changed νπ to ντι", r'νπ', r'ντι') #Fixes 'Γι’' when PDFd as ΓΓ CorrectText("Changed ΓΓ to Γι’", r'ΓΓ ', r'Γι’ ') #Fixes 'σχεδίαζ' when PDFd as σχέδιαζ CorrectText("Changed σχέδιαζ to σχεδίαζ", r'σχέδιαζ', r'σχεδίαζ') #Fixes '\u0388' when PDFd as 'E "E CorrectText("Changed 'E,\"E to \u0388", r'(\'|\")(\u0395)', r'Έ') #Fixes \u038E when PDFd as 'Y or "Y CorrectText("Changed 'Y,\"Y to \u038E", r'(\'|\")(\u03A5)', r'Ύ') #Fixes \u038A when PDFd as 'I or "I CorrectText("Changed 'I,\"I to \u038A", r'(\'|\")(\u0399)', r'Ί') #Fixes \u038C when PDFd as 'O or "O CorrectText("Changed 'O,\"O to \u038C", r'(\'|\")(\u039F)', r'Ό') #Fixes \u0386 when PDFd as 'A or "A CorrectText("Changed 'A,\"A to \u0386", r'(\'|\")(\u0391)', r'Ά') #Fixes \u0389 when PDFd as 'H or "H CorrectText("Changed 'H,\"H to \u0389", r'(\'|")(\u0397)', r'Ή') #Fixes \u038F when PDFd as '\u03C9 or "\u03C9 CorrectText("Changed '\u03C9,\"\u03C9 to \u038F", r'(\'|\")(\u03C9)', r'Ώ') #Fixes \u03CD when PDFd as \u03B0 CorrectText("Changed \u03CD to \u03B0", r'ΰ', r'ύ') #Fixes \u03CD when PDFd as \u03B0 CorrectText("Changed ε' to έ", r'ε\'', r'έ') #Fixes ς Character when PDFd as ςCharacter CorrectText("Changed ςCharacter to ς Character", r'ς([\u0370-\u03CE])', r'ς \1') Last edited by gipsy; 09-15-2015 at 06:38 AM. |
Advert | |
|
09-16-2015, 02:35 PM | #48 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
I have updated the plugin in the first post to include the latest changes for Greek texts from gipsy.
Thanks for pointing out that it may be necessary to delete any leftover ePubTidyTool.json files, Doitsu. I will add that advice to the epub guide for this plugin when I next update it. |
09-18-2015, 10:05 AM | #49 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
I have updated the plugin in the first post so that images in an ePub can be resized.
This will require the PILlow image library from https://pypi.python.org/pypi/Pillow/2.9.0 I decided to make the plugin 'beep' if an alphabetical character is inserted in an entry box for image size; as there is not a 'beep' facility within Python I had to produce a 'beep' that is system dependent. I have only been able to test this on Windows 7, hopefully this will work on Linux (I believe it will be necessary to install sox for the 'beep') and Mac systems too. One problem I had with the code for resizing the image was that I could not seem to read the image file using bk.readfile() into a buffer that PILow could process [I experimented with frombytes(), frombuffer() and fromarray()] so I resorted to saving the original image to disc and opening it again under PILow - not an ideal process. The ePub manual in the first post contains instructions on how to use the new feature. |
09-18-2015, 10:12 AM | #50 | |
Sigil Developer
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Quote:
At least, that is what it should do. I will look at the launcher code to make sure that is really what is happening, just in case. I have no idea how data is passed to Pillow but if it wants a file you should be able to use StringIO with with bk.readfile() returns from an image. I will look into this in case a fix is needed. Thanks, KevinH |
|
Advert | |
|
09-18-2015, 11:51 AM | #51 | |
Grand Sorcerer
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
For example: Code:
from PIL import Image from io import BytesIO def run(bk): data = bk.readfile('cover.jpg') img = Image.open(BytesIO(data)) (width, height) = img.size print(width, height) |
|
09-18-2015, 02:32 PM | #52 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
Thanks, Doitsu, this method allows me to read an image from an epub into img. After resizing the image, how can I write it back in a format that bk.writefile() can use? I've tried a few approaches including bkimage = BytesIO(self.img ) but without success.
|
09-18-2015, 03:21 PM | #53 | |
Grand Sorcerer
Posts: 5,584
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
Code:
from PIL import Image from io import BytesIO def run(bk): data = bk.readfile('cover.jpg') img = Image.open(BytesIO(data)) img.thumbnail((330, 330), Image.ANTIALIAS) imagedata = BytesIO() img.save(imagedata, 'png') thumbnail = imagedata.getvalue() bk.addfile('thumbnail.png', 'thumbnail.png', thumbnail, 'image/png') Last edited by Doitsu; 09-18-2015 at 03:50 PM. Reason: Code updated for Python 3.4 |
|
09-18-2015, 05:08 PM | #54 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
Thanks, Doitsu. I will try to get something to work for jpg files when I have more time.
|
09-18-2015, 09:33 PM | #55 |
Sigil Developer
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Hi,
The launcher code is correct. Doitsu is correct BytesIO is the way to go. Don't forget BytesIO gives a filedescriptor like interface so after writing to it don't forget to do seek(0) with it before trying to read from it after writing. Also when passing in data using BytesIO don't forget to pass in image format type to Image since it can't see a file extension that would convey the image type info. See some examples in Pillow's docs or via a google search for more info. If you run into difficulty, post some code and I'd be happy to figure out what is going on. KevinH |
09-20-2015, 02:03 PM | #56 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
I have improved the code in the plugin for resizing images so that temporary files are not written to disc (thanks to Doitsu and KevinH) as in my previous version. The updated plugin is in the first post of this thread.
Technical note: As Doitsu pointed out, "img.save() doesn't appear to work with jpg as the file format." According to information on the internet, the format of the jpg file is the same as for jpeg (early versions of Windows could not handle four character extensions as could other OS, so jpg was used as an extension for Windows. As modern Windows can handle four character extensions this is no longer a problem and it seems that Python uses jpeg only, so by treating jpg files as jpeg files, I have made the plugin work with jpg file extensions). |
09-20-2015, 06:08 PM | #57 |
Sigil Developer
Posts: 7,644
Karma: 5433388
Join Date: Nov 2009
Device: many
|
Hi,
When using BytesIO() there is no filename or extension. Therefore you must tell the Image routine the type of image you are reading in or saving. These are not the same as file extensions. The format for the .jpg, .jpeg, etc file extension is provided by the value "JPEG". So to save a jpeg (.jpg) image to a BytesIO() object you should always use "JPEG" as the requested output format. If you work with actual files then the file extension is used in place of the format info. Hope this explains things. If interested Pillow can be found on github and you can see the source. KevinH |
09-21-2015, 02:11 PM | #58 |
Addict
Posts: 201
Karma: 62362
Join Date: Jul 2015
Device: Sony
|
Thanks for the clarification, KevinH.
|
09-21-2015, 03:02 PM | #59 |
Connoisseur
Posts: 81
Karma: 10
Join Date: Nov 2013
Device: Kobo Aura HD
|
Hi,
I tried to add another span replacement. If you have a <span style="font-variant:small-caps;"> to replace it with \U\1\E but it doesn't work :P I add a Code:
elif comboBox[i].get() == "Change to UPPER": tagtoprocess=spanTagList[i]+"(.*?)</span>" html=re.sub(tagtoprocess, r'\U\1\E', html) I search and i found that if you want the Code:
\Uabc\Edef Code:
re.search("abc".upper() + "def", var) Thanks! |
09-23-2015, 03:57 AM | #60 |
Connoisseur
Posts: 81
Karma: 10
Join Date: Nov 2013
Device: Kobo Aura HD
|
CalibUser is possible to use the code for the hypens fix with other character?
For example... Sometimes you get Code:
"ύ" instead of "έ" "ο" instead of "σ" Thanks |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Tidying Up My Kindle | selectortone | Calibre | 2 | 07-17-2013 10:35 AM |
developping a Plugin for Presentation files | abdlink | Plugins | 4 | 04-15-2013 11:27 AM |
Plugin to fix fb2 files | oviksna | Plugins | 3 | 01-28-2013 08:53 AM |
Tidying Up My Library | JayLaFunk | Library Management | 2 | 09-20-2011 09:12 AM |
Calibre 0.7.50 can't see plugin files | mb_webguy | Calibre | 5 | 04-29-2011 03:41 AM |