Skip to content

Commit 535bf1d

Browse files
committed
Optimizer: Always replace images to ensure baseline JPEG encoding
1 parent ecf769d commit 535bf1d

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ A tool for converting EPUB files to XTC/XTCH format and optimizing EPUBs for e-i
3131
- Resize images to configurable max width/height
3232
- Flatten alpha transparency to white background
3333
- Skip tiny decorative images (<20px)
34-
- Only replace images when processed version is smaller
34+
- Re-encode images to baseline JPEG (required by e-paper devices)
3535
- Remove unsupported image formats (SVG, WebP, TIFF)
3636
- Inject e-paper optimized CSS
3737
- Batch processing with ZIP export

cli/optimizer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ async function optimizeEpub(inputPath, outputPath, options) {
283283
if (options.processImages && /\.(jpg|jpeg|png|bmp)$/i.test(filePath)) {
284284
const imgData = await zipFile.async('nodebuffer');
285285
const processed = await processImage(imgData, options.maxImageWidth, options.grayscale);
286-
if (processed && processed.length < imgData.length) {
286+
if (processed) {
287287
// Output is always JPEG — rename non-JPEG files to avoid content-type mismatch
288288
if (/\.(png|bmp)$/i.test(filePath)) {
289289
const jpegPath = filePath.replace(/\.[^.]+$/, '.jpg');
@@ -292,6 +292,8 @@ async function optimizeEpub(inputPath, outputPath, options) {
292292
imageRenames[filePath] = jpegPath;
293293
ops.push({ type: 'convertImage', file: filePath, to: jpegPath });
294294
} else {
295+
// Always replace JPEGs — device requires baseline encoding
296+
// (progressive and arithmetic JPEGs are re-encoded to baseline by Sharp)
295297
epubZip.file(filePath, processed);
296298
ops.push({ type: 'processImage', file: filePath });
297299
}

web/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1814,7 +1814,7 @@ async function optimizeEpub(file) {
18141814
if (settings.processImages && /\.(jpg|jpeg|png|bmp|gif)$/i.test(path)) {
18151815
var imgData = await zipFile.async('arraybuffer');
18161816
var processedImg = await processImage(imgData, settings.maxWidth, settings.grayscale);
1817-
if (processedImg && processedImg.byteLength < imgData.byteLength) {
1817+
if (processedImg) {
18181818
epubZip.file(path, processedImg);
18191819
}
18201820
}

0 commit comments

Comments
 (0)