Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 01-31-2023, 07:34 PM   #1
tatagi
Connoisseur
tatagi began at the beginning.
 
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.
tatagi is offline   Reply With Quote
Old 01-31-2023, 10:07 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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
kovidgoyal is offline   Reply With Quote
Advert
Old 02-01-2023, 12:51 PM   #3
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
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
isarl is offline   Reply With Quote
Old 02-01-2023, 07:01 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
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.
kovidgoyal is offline   Reply With Quote
Old 02-01-2023, 07:38 PM   #5
tatagi
Connoisseur
tatagi began at the beginning.
 
Posts: 52
Karma: 10
Join Date: Oct 2022
Device: none
Quote:
Originally Posted by isarl View Post
.
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

Quote:
Originally Posted by kovidgoyal View Post
.
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.
tatagi is offline   Reply With Quote
Advert
Old 02-01-2023, 08:08 PM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
yes, png will be compressed losslessly regardless of that checkbox
kovidgoyal is offline   Reply With Quote
Old 02-02-2023, 04:44 AM   #7
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,727
Karma: 24031401
Join Date: Dec 2010
Device: Kindle PW2
Quote:
Originally Posted by tatagi View Post
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.
Shameless plug: if you want to experiment with lossy .png compression, you might find my pngquant-based PNGOptimizer plugin for Sigil helpful.
Doitsu is offline   Reply With Quote
Old 02-02-2023, 09:04 AM   #8
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
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:
Originally Posted by isarl View Post
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.

(I guess I didn't end up using xargs after all – find kind of has it built-in.)
Why are you going 300x300 maximum? That makes higer resolution images way too small. I highly suggest you don't do that.
JSWolf is offline   Reply With Quote
Old 02-02-2023, 09:26 AM   #9
isarl
Addict
isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.isarl ought to be getting tired of karma fortunes by now.
 
Posts: 287
Karma: 2534928
Join Date: Nov 2022
Location: Canada
Device: Kobo Aura 2
Quote:
Originally Posted by JSWolf View Post
Why are you going 300x300 maximum? That makes higer resolution images way too small. I highly suggest you don't do that.
It was simply numbers to illustrate and be replaced according to the wishes of whomever runs it. I'm not executing this on my own library but would expect the same thing you suggest, that 300 pixels on the long side is too small. Thanks for looking out.
isarl is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 12:00 PM.


MobileRead.com is a privately owned, operated and funded community.