Getting and setting the cover image from an EPUB file
I’ve only done this with a small number of EPUB files, but it seems to work so far.
How to get the cover from an EPUB file
- Find the
content.opf
file. -
Look for an
<item properties="cover-image" …>
element in the<manifest>
, which will point to the path to the cover image, for example:<item id="cover-image" properties="cover-image" href="media/cover.png" media-type="image/png"/>
How to set the cover in an EPUB file
- Add the cover image to the EPUB package.
- Find the
content.opf
file. -
Add an
<item properties="cover-image" …>
element in the<manifest>
which points to the cover image you’ve added:<item id="cover-image" properties="cover-image" href="media/cover.png" media-type="image/png"/>
-
Add a
<meta name="cover" …>
element in the<metadata>
which points to the<manifest>
element you just added:<meta name="cover" content="cover-image"/>
Don’t use pandoc
While researching this question, I asked Claude hwo to solve this. It suggested using pandoc
pandoc input.epub -o output.epub --epub-cover-image=cover.png
I was already dubious because pandoc is a big dependency to add to an app, but even more so when I realised that this mangles the formatting.