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
|