![]() |
#1 |
Connoisseur
![]() Posts: 52
Karma: 10
Join Date: Oct 2022
Device: none
|
Compress only specified img formats, possible?
I don't know if this is normal but when I used calibre editor tool "compress image losslessly" and checked "enable lossy compression of jpeg images" I personally experienced slow compressions of images in PNG formats somehow.
The quality is set to 80 which in my opinion is the best risk-benefit ratio. It works well with most of images in jpg/jpeg formats, but for png files, the compression rate is very minimal (only reduction of 3 to 5 percent on average) and the process takes much longer to finish than jpg format. Furthermore, unlike the option tells about itself, not only jpeg but also other img formats are processed. The best shot to take is to open "compress image" tool, and then check through each image to select only jpg images to compress and click OK. It does its job but too time and effort consuming. I usually prefer to get things done on command line to process files in bulk. Any ideas? Last edited by tatagi; 01-31-2023 at 07:36 PM. |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
There is no lossy compression for PNG files. That option affects only JPEG
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
If you are willing to do more work from the commandline then epubs make this pretty easy. Every epub file is also a zip file which you can simply unzip into a directory. You could then run in-place image compression only on files matching a regular expression, like \.jpe?g$, then re-zip the file. Of course, doing it this way will be destructive, so proceed with caution.
I would likely do this using a combination of the following tools: find and its -execdir option, unzip, xargs, and ImageMagick's mogrify. For a single book, this might look like: unzip book.epub -d tmp_book cd tmp_book find . -iname "*.jpeg" -iname "*.jpg" -execdir mogrify -define jpeg:extent=300KB -size 300x300 '{}' ';' zip new_book * mv new_book.zip .. cd .. rm -rf tmp_book The options I specified to mogrify here will enforce a maximum filesize of 300KB, and a maximum image geometry of 300×300. It will preserve the aspect ratio, using each value as a maximum – this command will not force your images to be square. I just happened to choose equal maxwidth and maxheight. You can customize the numbers in the command above to suit your own preference, as 300 pixels is likely too small. (I guess I didn't end up using xargs after all – find kind of has it built-in.) Last edited by isarl; 02-02-2023 at 09:49 AM. Reason: Clarify that the numbers are example numbers intended to be adjusted |
![]() |
![]() |
![]() |
#4 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You dont need to mess with zip/unzip.
calibre-debug --explode-book will handle those bits for you. |
![]() |
![]() |
![]() |
#5 |
Connoisseur
![]() Posts: 52
Karma: 10
Join Date: Oct 2022
Device: none
|
thanks for information. I assume the command you specified is for Unix system probably. I am running Windows PC but ImageMagick supports windows os too so I will check that out. and yes I always want as minimal changes to be made for my document as possible. that's why I never resize images for that matter, and only keep compression level in mind
![]() thanks about that. so assuming there is a epub document that contains both jpg and png files formats and I check lossy compression, it means jpg is lossy compressed and png is losslessly compressed respectively? I am afraid so because after the compression successfully finished and when I check the file size, png files also cut down by 3-5% and the date modified also changes. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
yes, png will be compressed losslessly regardless of that checkbox
|
![]() |
![]() |
![]() |
#7 | |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 5,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
|
Quote:
|
|
![]() |
![]() |
![]() |
#8 | |
Resident Curmudgeon
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
|
Quote:
|
|
![]() |
![]() |
![]() |
#9 | |
Addict
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
|
Quote:
![]() |
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Compress images | endemion06463 | Conversion | 18 | 04-23-2024 04:55 AM |
Can I compress pdf with calibre? | tatagi | Calibre | 1 | 01-26-2023 02:56 AM |
How to not compress jpeg | Arrandir | Sigil | 5 | 04-11-2020 06:43 PM |
4.11.1 right click img in editor to edit img | rjwse@aol.com | Calibre | 1 | 02-21-2020 09:29 PM |
Can Calibre compress ePub? | marty1990 | Calibre | 2 | 06-09-2012 06:52 AM |