View Single Post
Old 05-12-2016, 11:22 AM   #13
jackie_w
Grand Sorcerer
jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.jackie_w ought to be getting tired of karma fortunes by now.
 
Posts: 6,212
Karma: 16534894
Join Date: Sep 2009
Location: UK
Device: Kobo: KA1, ClaraHD, Forma, Libra2, Clara2E. PocketBook: TouchHD3
@ Kovid,

I found a problem when using my ScrambleEbook plugin. The problem arises when trying to scramble GIF images (JPG, JPEG, PNG, SVG seem OK).

This is the error message:
Code:
calibre, version 2.56.0
ERROR: Unhandled exception: <b>TypeError</b>:file() argument 1 must be encoded string without NULL bytes, not str

calibre 2.56 [64bit]  embedded-python: True is64bit: True
Windows-7-6.1.7601-SP1 Windows ('64bit', 'WindowsPE')
('Windows', '7', '6.1.7601')
Python 2.7.9
Windows: ('7', '6.1.7601', 'SP1', 'Multiprocessor Free')
Successfully initialized third party plugins: DeDRM && Obok DeDRM && ScrambleEbook && Fantastic Fiction && Goodreads && JS Mod Epub && Diaps Editing Toolbag && DOC Input && KePub Metadata Writer && Barnes & Noble && Search The Internet && Count Pages && Wiki Reader && Quality Check && Open With && Copy Cover To Device && EpubSplit && JSTest Plugin && KindleUnpack - The Plugin && KePub Metadata Reader && Extract ISBN && KePub Input && Modify ePub && KoboTouchCSSEdit && Kobo Utilities && KePub Output && KoboBooks
Traceback (most recent call last):
  File "calibre_plugins.scrambleebook_plugin.scrambleebook", line 334, in create_scramble_book
  File "calibre_plugins.scrambleebook_plugin.scrambleebook", line 409, in __init__
  File "calibre_plugins.scrambleebook_plugin.scrambleebook", line 437, in scramble_main
  File "calibre_plugins.scrambleebook_plugin.scrambleebook", line 540, in scramble_img
  File "site-packages\calibre\utils\magick\legacy.py", line 135, in export
  File "site-packages\Pillow-2.4.0-py2.7-win-amd64.egg\PIL\Image.py", line 2093, in open
TypeError: file() argument 1 must be encoded string without NULL bytes, not str

This is the Python method where the error occurs (the red line). It processes all image formats except .SVG:
Spoiler:
Code:
def scramble_img(self, name, scramble_dgts=False):
    if self.eb.mime_map[name] in OEB_RASTER_IMAGES:
        data = self.eb.parsed(name)
        oldimg = Image()
        oldpath = self.eb.name_to_abspath(name)
        try:
            oldimg.load(data)
            wid, hgt = oldimg.size
        except:
            wid, hgt = (50, 50)
        try:
            fmt = oldimg.format
        except:
            x, x, fmt = get_nameparts(name)
        
        newimg = Image()
        newimg.load(self.dummyimg)
        newimg.size = (wid, hgt)
        
        self.eb.replace(name, newimg.export(fmt.upper()))

  • The relevant import: from calibre.utils.magick import Image
  • self.eb is a standard calibre container object (epub/azw)

I've attached a test epub in case you need it.
Attached Files
File Type: epub Images_test.epub (436.8 KB, 213 views)

Last edited by jackie_w; 05-12-2016 at 12:45 PM. Reason: Can't even get the name of my own plugin right!
jackie_w is offline   Reply With Quote