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.1',
+ 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',
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(),