Fight for the Internet 1!

Friday, August 19, 2016

Fix Misaligned ePub Cover

Recently I had some ePub files that had misaligned tiny cover images. I wanted to correct this. Here's a really simple fix for many cases.

I use Calibre as my eBook reader, and it has an option to "Edit book", which will take you to the digital book file editor.

Notice the panel on the left upper area, labeled File Browser. Usually the first file in this list is the Cover html page file. Also in the middle of the left column, an area labeled Images.

Automatically Recreating the Cover
If you have a copy of the book cover (which is trivially easy thanks to Google), I suggest you just delete the first titlepage.html cover file (or whatever it is called), and the related image file under the image section.

Then go to Menu: Tools --> Add cover.

Then import the cover image, and check the option to preserve the aspect ratio.

Manually Editing the Image Alignment
Double click to open it. You may see something similar to this:

<html xmlns="">
  <meta content="ABBYY FineReader 11" name="generator" />
  <link href="Court_of_all_Shamens_files/Court_of_all_Shamens.css" rel="stylesheet" type="text/css" />


  <p><img alt="9785567648623" src="../Images/9785567648623.jpg" /><br />

The problem here is the image is just dropped into the document without any helpful formatting to make it full-sized. With a few tweaks in the code, you can make it much more aesthetically pleasing.

In the <head> section, add the <style> section:

    <style type="text/css">
@page {padding: 0pt; margin:0pt}
                        body { text-align: center; padding:0pt; margin: 0pt; }

In the <body> section, just drop in this code snippet, but replace the src="" contents with the image file in your file. Example:

    <svg xmlns="" height="100%" version="1.1" viewBox="0 0 316 532" width="100%" xmlns:xlink="">
    <image height="532" width="316" xlink:href="../Images/9785567648623.jpg"></image>

This should center and enlarge your cover image properly.

No comments:

Post a Comment