diff --git a/resources/default_tweaks.py b/resources/default_tweaks.py index 98cdccf164..48845da920 100644 --- a/resources/default_tweaks.py +++ b/resources/default_tweaks.py @@ -88,8 +88,9 @@ save_template_title_series_sorting = 'library_order' # separated by 'or' bars. Comparisons are case insensitive, and that cannot be # changed. Changes to this tweak won't have an effect until the book is modified # in some way. If you enter an invalid pattern, it is silently ignored. +# To disable use the expression: '^$' # Default: '^(A|The|An)\s+' -title_sort_articles='^(A|The|An)\s+' +title_sort_articles=r'^(A|The|An)\s+' # Specify a folder that calibre should connect to at startup using diff --git a/resources/recipes/rmf24_opinie.recipe b/resources/recipes/rmf24_opinie.recipe index 4d2f447dbe..9e4d336252 100644 --- a/resources/recipes/rmf24_opinie.recipe +++ b/resources/recipes/rmf24_opinie.recipe @@ -42,7 +42,7 @@ class RMF24_opinie(BasicNewsRecipe): # thanks to Kovid Goyal def get_article_url(self, article): link = article.get('link') - if 'audio' not in link: + if '/audio,aId' not in link: return link preprocess_regexps = [ diff --git a/src/calibre/ebooks/mobi/output.py b/src/calibre/ebooks/mobi/output.py index d82704a0df..49da18ea7b 100644 --- a/src/calibre/ebooks/mobi/output.py +++ b/src/calibre/ebooks/mobi/output.py @@ -41,24 +41,6 @@ class MOBIOutput(OutputFormatPlugin): ), ]) - def remove_image_transparencies(self): - from calibre.utils.magick.draw import save_cover_data_to - for item in self.oeb.manifest: - if item.media_type.startswith('image'): - raw = item.data - ext = item.media_type.split('/')[-1].lower() - if ext not in ('png', 'gif') or not raw: - continue - try: - data = save_cover_data_to(raw, 'img.'+ext, return_data=True) - except: - self.log.exception('Failed to remove transparency from', - item.href) - data = None - if data is not None: - item.data = data - item.unload_data_from_memory() - def check_for_periodical(self): if self.oeb.metadata.publication_type and \ unicode(self.oeb.metadata.publication_type[0]).startswith('periodical:'): @@ -178,7 +160,6 @@ class MOBIOutput(OutputFormatPlugin): from calibre.ebooks.oeb.transforms.rasterize import SVGRasterizer, Unavailable from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder from calibre.customize.ui import plugin_for_input_format - self.remove_image_transparencies() imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None if not opts.no_inline_toc: tocadder = HTMLTOCAdder(title=opts.toc_title) diff --git a/src/calibre/ebooks/mobi/writer.py b/src/calibre/ebooks/mobi/writer.py index 51639ac757..e8fc4557fd 100644 --- a/src/calibre/ebooks/mobi/writer.py +++ b/src/calibre/ebooks/mobi/writer.py @@ -15,7 +15,6 @@ from struct import pack import time from urlparse import urldefrag -from PIL import Image from cStringIO import StringIO from calibre.ebooks.mobi.langcodes import iana2mobi from calibre.ebooks.mobi.mobiml import MBP_NS @@ -28,6 +27,7 @@ from calibre.ebooks.oeb.base import namespace from calibre.ebooks.oeb.base import prefixname from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.compression.palmdoc import compress_doc +from calibre.utils.magick.draw import Image, save_cover_data_to, thumbnail INDEXING = True FCIS_FLIS = True @@ -111,46 +111,18 @@ def align_block(raw, multiple=4, pad='\0'): return raw + pad*(multiple - extra) def rescale_image(data, maxsizeb, dimen=None): - image = Image.open(StringIO(data)) - format = image.format - changed = False - if image.format not in ('JPEG', 'GIF'): - width, height = image.size - area = width * height - if area <= 40000: - format = 'GIF' - else: - image = image.convert('RGBA') - format = 'JPEG' - changed = True if dimen is not None: - image.thumbnail(dimen, Image.ANTIALIAS) - changed = True - if changed: - data = StringIO() - image.save(data, format) - data = data.getvalue() - if len(data) <= maxsizeb: - return data - image = image.convert('RGBA') - for quality in xrange(95, -1, -1): - data = StringIO() - image.save(data, 'JPEG', quality=quality) - data = data.getvalue() - if len(data) <= maxsizeb: - return data - width, height = image.size - for scale in xrange(99, 0, -1): - scale = scale / 100. - data = StringIO() - scaled = image.copy() - size = (int(width * scale), (height * scale)) - scaled.thumbnail(size, Image.ANTIALIAS) - scaled.save(data, 'JPEG', quality=0) - data = data.getvalue() - if len(data) <= maxsizeb: - return data - # Well, we tried? + return thumbnail(data, width=dimen, height=dimen)[-1] + # Replace transparent pixels with white pixels and convert to JPEG + data = save_cover_data_to(data, 'img.jpg', return_data=True) + scale = 0.9 + while len(data) >= maxsizeb and scale >= 0.05: + img = Image() + img.load(data) + w, h = img.size + img.size = (int(scale*w), int(scale*h)) + data = img.export('jpg') + scale -= 0.05 return data class Serializer(object):