How to make a Kindle eBook full of images

Here at Kindle Maps, I'm trying to make maps from OpenStreetMap and put them on the Amazon Kindle, like an off-line street atlas. EBook readers are great for text because you can reflow the text, and increase the font size, etc. However a street atlas will not have any of this because each page is one image.

I created the images from OpenStreetMap data and tools, using a customized version of generate_image.py, and then converted the images to PDF. However Amazon's PDF converter messed that up.

Amazon HTML

Amazon seem to internally use a slight dialect of HTML to process the books. When they convert your book from PDF (or MS Word, etc.), they give you a zip file of HTML & images in this format. Rather than generate a PDF for Amazon to convert, I decided to use their HTML format directly.

Assuming you have a several images named page1.png, page2.png, etc., one image for each page, and you want each image on it's own page, the HTML file should be like this:

<html><body>
<img src="page1.png" middle /><mbp:pagebreak />
<img src="page2.png" middle /><mbp:pagebreak />
<img src="page3.png" middle /><mbp:pagebreak />
<img src="page4.png" middle /><mbp:pagebreak />
</body></html>

Save that as book.html (or whatever name you want) in a folder alongside all the image pages.

Image Layout

Amazon have a page on image placements, and I've added the middle tag to the <img… to get the images to appear centred vertically. Images should be less than 127KiB, however I've used images of 200KiB and it's all worked out. They might be downsized in the conversion process later, I don't know.

Custom HTML

I'm using the <mbp:pagebreak />, which is one of Amazon's custom HTML tags, which (obviously) inserts a page break and starts a new page. This should 'force' each image to be on a new page, rather than Amazon's convertor programme merging, cropping and combining images to wreck your images.

Converting HTML to .mobi for upload

Once you have a folder with the above HTML file and images, download KindleGen (scroll down). It's a command line programme for Linux, Windows and Mac OSX that converts that HTML and images into a .mobi ebook file.

Download the .tar.gz, unzip it, cd into directory with the HTML and images, and run the kindlegen programme like this:

/where/you/unzipped/the/tarbal/kindlegen book.html

This will then create a file book.mobi, a self contained file that includes all the layout and the images.

Preview

You can then preview this .mobi file on your Kindle and check that it all works OK, and then upload that file to Amazon's KDP.

Comments !

blogroll