03-23-2023, 06:16 AM | #1 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2023
Device: kobo clara hd
|
Avoid loss with jpeg
I have a bunch of comics in cbz format (jpeg encoded), that I would like to optimize for reading on my ereader. Using calibre, I can trim the images to remove the white border and rotate landscape pages so that they fill my screen. However, both options require reencoding the images, which results in ugly artifacts and/or bigger files than the originals.
It should be possible to perfectly preserve the content of the image without increasing filesize by: 1. Only cropping the borders by multiples of 8x8 blocks 2. Using the rotation metadata instead of modifying the pixels Is it possible to do that from within calibre? Alternatively, is there any tool to do that on linux? I could write a script for the second part using imagemagick's "identify" and exiftool, but I couldn't find how to do the first part. |
03-23-2023, 06:44 AM | #2 |
creator of calibre
Posts: 43,996
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
No, it's not possible within calibre.
|
03-23-2023, 09:33 AM | #3 |
Junior Member
Posts: 9
Karma: 10
Join Date: Mar 2023
Device: kobo clara hd
|
Thanks. I'll try and see if I can write a plugin then. In the meanwhile, I managed to write a shell script to convert a file how I want (requires imagemagick and jpegtran). It turned out that my e-reader doesn't read exif metadata, so I have to actually rotate the image.
Code:
#!/bin/sh infile="$1" outfile="$2" croparea=$(convert "$infile" -fuzz 10% +repage -trim -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]\n' info:) jpegtran -outfile tmp.jpg -progressive -arithmetic -crop $croparea "$infile" read -r width height << EOF $(identify -format "%w %h\n" $outfile) EOF if [ $width -gt $height ]; then jpegtran -outfile "$outfile" -progressive -arithmetic -rotate 90 tmp.jpg fi rm -f tmp.jpg |
Tags |
cbz, exif, jpeg |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to not compress jpeg | Arrandir | Sigil | 5 | 04-11-2020 06:43 PM |
Jpeg displaying | GlenWeb | ePub | 12 | 06-18-2019 03:17 PM |
Inserting a jpeg into a PM | Lynx-lynx | Feedback | 11 | 12-24-2014 06:17 AM |
JPEG lockups | jakeluck | Sony Reader | 0 | 11-25-2006 03:24 PM |