Merge from trunk

This commit is contained in:
Charles Haley 2010-10-03 19:59:44 +01:00
commit cf714e3968
4 changed files with 15 additions and 61 deletions

View File

@ -88,8 +88,9 @@ save_template_title_series_sorting = 'library_order'
# separated by 'or' bars. Comparisons are case insensitive, and that cannot be # 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 # 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. # in some way. If you enter an invalid pattern, it is silently ignored.
# To disable use the expression: '^$'
# Default: '^(A|The|An)\s+' # 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 # Specify a folder that calibre should connect to at startup using

View File

@ -42,7 +42,7 @@ class RMF24_opinie(BasicNewsRecipe):
# thanks to Kovid Goyal # thanks to Kovid Goyal
def get_article_url(self, article): def get_article_url(self, article):
link = article.get('link') link = article.get('link')
if 'audio' not in link: if '/audio,aId' not in link:
return link return link
preprocess_regexps = [ preprocess_regexps = [

View File

@ -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): def check_for_periodical(self):
if self.oeb.metadata.publication_type and \ if self.oeb.metadata.publication_type and \
unicode(self.oeb.metadata.publication_type[0]).startswith('periodical:'): 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.rasterize import SVGRasterizer, Unavailable
from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder from calibre.ebooks.oeb.transforms.htmltoc import HTMLTOCAdder
from calibre.customize.ui import plugin_for_input_format from calibre.customize.ui import plugin_for_input_format
self.remove_image_transparencies()
imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None imagemax = PALM_MAX_IMAGE_SIZE if opts.rescale_images else None
if not opts.no_inline_toc: if not opts.no_inline_toc:
tocadder = HTMLTOCAdder(title=opts.toc_title) tocadder = HTMLTOCAdder(title=opts.toc_title)

View File

@ -15,7 +15,6 @@ from struct import pack
import time import time
from urlparse import urldefrag from urlparse import urldefrag
from PIL import Image
from cStringIO import StringIO from cStringIO import StringIO
from calibre.ebooks.mobi.langcodes import iana2mobi from calibre.ebooks.mobi.langcodes import iana2mobi
from calibre.ebooks.mobi.mobiml import MBP_NS 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 prefixname
from calibre.ebooks.oeb.base import urlnormalize from calibre.ebooks.oeb.base import urlnormalize
from calibre.ebooks.compression.palmdoc import compress_doc from calibre.ebooks.compression.palmdoc import compress_doc
from calibre.utils.magick.draw import Image, save_cover_data_to, thumbnail
INDEXING = True INDEXING = True
FCIS_FLIS = True FCIS_FLIS = True
@ -111,46 +111,18 @@ def align_block(raw, multiple=4, pad='\0'):
return raw + pad*(multiple - extra) return raw + pad*(multiple - extra)
def rescale_image(data, maxsizeb, dimen=None): 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: if dimen is not None:
image.thumbnail(dimen, Image.ANTIALIAS) return thumbnail(data, width=dimen, height=dimen)[-1]
changed = True # Replace transparent pixels with white pixels and convert to JPEG
if changed: data = save_cover_data_to(data, 'img.jpg', return_data=True)
data = StringIO() scale = 0.9
image.save(data, format) while len(data) >= maxsizeb and scale >= 0.05:
data = data.getvalue() img = Image()
if len(data) <= maxsizeb: img.load(data)
return data w, h = img.size
image = image.convert('RGBA') img.size = (int(scale*w), int(scale*h))
for quality in xrange(95, -1, -1): data = img.export('jpg')
data = StringIO() scale -= 0.05
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 data return data
class Serializer(object): class Serializer(object):