Mobileread
How to bulk replace images in EPUB?
#1  mathil 12-14-2019, 12:37 PM
Some of the epubs I've bought have .png images. I've been trying to convert and substitute them with their .jpeg equivalent (same file name, different format), but the only way I can seem to be doing so with no hassle is through Calibre Editor using the 'substitute image' option. However, that is quite slow as there's no batch option for doing that, and I have one particular epub that contains 200+ images.
Is there a way I can substitute all of them in one go and still have a functioning epub at the end?
Reply 

#2  Turtle91 12-14-2019, 01:56 PM
Be careful when substituting - sometimes the book creator uses png for a specific reason, eg. .png can have transparent backgrounds so the image works with whatever color background the user selects, while jpg does not.

Code
- you will need to do the conversion from .png to .jpg using your favorite image
software/process and put them in an accessible location/folder
- open the epub file manually: -- rename the file from yourfilename.epub to yourfilename.zip -- open the zip file, find the image files and delete (sometimes they are located in: ../OEBPS/Images/) -- copy the new/changed images to that folder -- rename the file back to an .epub extension - OR -
- you can accomplish this step using Sigil by multi-selecting all the files you want to delete (ctrl-click or shift-click) in the Book Browser Pane then hitting the delete key. Then using the "add existing files" button (plus sign on the toolbar, or Insert/File on the menu, or Ctrl-shift-I) then multi-select all the images you wish to add then selecting "open"
- Once the images are in your epub use your editor of choice (Sigil or Calibre Editor are excellent, free, editors) to change the file reference in the html: -- search for something like: Images/(.*?).png" -- replace with something like: Images/\1.jpg"
You should definitely do this on a backup copy of your book, and I would recommend iterating through one at a time (replace/find instead of replace all).
Reply 

#3  exaltedwombat 12-15-2019, 07:30 PM
Out of interest, why?
Reply 

Today's Posts | Search this Thread | Login | Register