This document records all notable changes to Librarian.
+## 24.5
+
+- Smaller images in EPUB (600px width instead of 1200px).
+- Convert PNG to JPEGs if too large in EPUBs.
+
## 24.4
- Add fundraising inserts in PDF.
setup(
name='librarian',
- version='24.4',
+ version='24.5',
description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
author="Marek Stępniowski",
author_email='marek@stepniowski.com',
"""
EXPR = re.compile(r'/\s', re.MULTILINE | re.UNICODE)
def _compat_assign_ordered_ids_in_elem(elem, i):
+ if isinstance(elem, etree._Comment): return i
elem.attrib['_compat_ordered_id'] = str(i)
i += 1
if getattr(elem, 'HTML_CLASS', None) == 'stanza':
from ..base import WLElement
+MAX_PNG_WEIGHT = 200000
+
+
class Ilustr(WLElement):
SHOULD_HAVE_ID = True
'PNG': ('PNG', 'png', 'image/png'),
}.get(img.format, ('JPEG', 'jpg', 'image/jpeg'))
- width = 1200
+ width = 600
if img.size[0] < width:
th = img
else:
buffer = io.BytesIO()
th.save(buffer, format=th_format)
+
+ # Limit PNG to 200K. If larger, convert to JPEG.
+ if th_format == 'PNG' and buffer.tell() > MAX_PNG_WEIGHT:
+ th_format, ext, media_type = 'JPEG', 'jpg', 'image/jpeg'
+ if th.mode != 'RGB':
+ buffer = io.BytesIO()
+ th = Image.alpha_composite(
+ Image.new('RGBA', th.size, '#fff'),
+ th.convert('RGBA')
+ )
+ th = th.convert('RGB')
+ th.save(buffer, format=th_format)
+
imgfile.close()
file_name = 'image%d.%s' % (
builder.assign_image_number(),
naglowek.addprevious(spot)
spots.append(spot)
spot = etree.Element('f_spot')
- doc.getroot()[-1][-1].append(spot)
+ doc.getroot()[-1].append(spot)
spots.append(spot)
e = len(spots)
nfunds = len(fundraising)