Tutorial: Saving Multiple Images to Target File Size for Kindle MOBI

In a recent project, I converted a graphic novel originally destined for print to EPUB and Kindle (MOBI) formats. The author/illustrator reformatted any spreads to work on single pages, and provided me with nearly 300 images, each each of which would be a single page in the ebook. Rather than creating a fixed-layout ebook, I found the more efficient route in terms of was to create a regular reflowable ebook in EPUB format, then after filling out the metadata and adding various code tweaks, converting it to Kindle format using Calibre.

I’ll talk more about the general process for creating an e-graphic novel in later posts, but for today I want to discuss a specific challenge I faced with this title – image file size restrictions in the Kindle, as well as overall file size restrictions.

In my first test conversion from EPUB to MOBI, I ended up with an ebook file that was 58.5 MB overall. From the Kindle Direct website:

The maximum file size for conversion through Amazon KDP is 50MB. All files larger than the 50MB limit will fail to convert. Here are some guidelines for reducing your file size. When uploading your book content to Kindle Direct Publishing (KDP) it is best to keep your file size below 50MB. Files over this recommended maximum may experience delays in conversion, or even fail to convert entirely.

I was pretty lucky that the file itself was not too much over 50 megabytes – I figured it wouldn’t be too difficult to get the overall file size under 50 MB as I was planning to run a batch conversion of all the book’s images from the raw format anyway in order to optimize them for Kindle devices. And in any case, after a little more reading on the KDP site I found:

Inside your book file, the Kindle book format supports JPEG and GIF images up to 127KB in size. Images that are in other formats supported for upload to KDP (such as BMP or PNG), or that exceed this file size requirement, will be automatically recompressed as JPEG files during the conversion process. Optimizing your images to fit these requirements before uploading to KDP will help decrease the size of your uploaded file. It will also reduce the chance of encountering difficulties in conversion due to large file size.

Many of my images were indeed larger than 127 kilobytes in size – but some were already under 127 KB. The amount of compression required for the JPEG format varies depending on the amount of detail in each image. These were greyscale illustrations that were sometimes very simple with a single panel, but more often consisted of six panels with a fair amount of detail and shading, as well as text.

I didn’t want to use more compression than I needed on any given image, because images with less detail will show JPEG artifacts at higher compression settings – I wanted to use just enough to get each image under the target file size of 127 KB. Obviously, I wasn’t going to convert 270 images one at a time, so I opened one of the largest images and I began recording an Action in Adobe Photoshop to reduce the dimensions of each image, remove any guides, adjust the levels slightly to increase contrast, and finally, save the file using Save for Web and Devices while a) stripping out any metadata to further reduce file size, and b) using the Optimize to File Size option to allow Photoshop to use only as much compression as required for each individual JPEG to fall under 127 KB.

Photoshop: Optimize to File Size
Photoshop: Optimize to File Size

It wasn’t long before I realized that the Optimize to File Size function could not be added to an Action. After some research online I found that this function cannot be added to a script either. There are ways to script a feature that will re-save the image repeatedly until the desired file size is attained, but this too seemed a lot more complicated than it needed to be.

There is software available that can perform this task, and for the sake of self-published authors out there who are working on little to no budget, I’ve documented a way of doing this using free software below. Unfortunately, this option is only for Windows users. I couldn’t find any equivalent method for the Mac, except perhaps the Photoshop script mentioned above.

First of all, you’ll need to download and install a simple image viewing and conversion application called IrfanView. It’s a nice little piece of software for simple viewing of images, but it also offers some nice features such as the creation of .ICO files with multiple sizes of image within (for displaying alongside your URL in the web browser address bar – I will cover this in a future post), and batch conversion of JPEG files. Once you’ve installed it, don’t run it yet. We’ll need to install a plugin to add the functionality we’re looking for.

The plugin we need is called RIOT: Radical Image Optimization Tool. I do not recommend that you download the installable version from the creator’s website as it contains OpenCandy recommendations for other software – this is not dangerous, but your virus scanner may identify this installer as malware. So, instead, we can download a stripped-down version of the plugin from IrfanView plugin page and simply install it ourselves. Use option 2 on this page – download all plugins as one large zip file to your desktop.

Save Irfanview plugin zip file
Save Irfanview plugin zip file

Once you’ve downloaded the zip file to your desktop, simply double-click on it to access the plugins inside. Locate Riot.dll. Right-click on it to open the contextual menu and select Copy.

Locate and copy Riot.dll plugin
Locate and copy Riot.dll plugin

Next, navigate to the IrfanView plugins folder. If you installed this software with the default options, the folder should be in the following location: C:\Program Files (x86)\IrfanView\Plugins. Hit CTRL-V to paste the file into that folder and don’t close the folder window just yet!

Navigate up one level to the main IrfanView folder, and double click on the i_view32.exe file to open the program. A side note: this is the basic IrfanView program – if you go to your Start menu and open the program called “Irfanview – Thumbnails” it’s a slightly different interface specifically for viewing images.

From the top menu in IrfanView, select File > Batch Conversion/Rename.

Irfanview: Batch Conversion option
Irfanview: Batch Conversion option

In the Batch Conversion window that appears, there are various settings you’ll have to adjust. First of all, in the image below, you’ll see the Look In section on the top right side of the window.

Irfanview Batch Conversion window
Irfanview Batch Conversion window

In the Look In file window, you’ll need to browse to the folder containing the image you want to convert, which I’ve done here: the mobi-version-renamed folder. I’ve previously renamed the image files to match the names of the files in the EPUB I’m preparing to convert to MOBI format using a program called Bulk Rename Utility. (This software is also Windows-only. I’ll be covering bulk file renaming in a future blog post. You can do this before or after the batch conversion.) Simply select one file, then hit CTRL-A to select all the files in that folder. Click the Add all button below the file window to add all of these image files to the Input files window on the lower right. Just to the left of that, I’ve already set a folder called mobi-version-reduced as my output directory.

Next, under Batch conversion settings on the upper left, ensure that JPG – JPG/JPEG Format is the selected format in the dropdown menu, then click the Options button.

Irfanview JPEG/GIF save options
Irfanview JPEG/GIF save options

In the JPEG/GIF save options window that appears, simply set the Save quality slider all the way to the right to ensure the file quality is as high as possible during the conversion, then set the file size to 126 KB. The Kindle limit is actually 127 KB, but I felt that I would like to have a 1 kilobyte buffer so that there is no chance the Kindle Direct converter will misjudge the file sizes. You don’t need to check any of the other boxes here – when ready, click OK, and then click the Start Batch button on the lower left of the Batch conversion window.

The Processing file window will then open to show you the file conversion progress. It will take a second or two for each image, depending on the processing power of your computer.

Irfanview: the file processing window
Irfanview: the file processing window

When it finishes, simply click the Exit batch button that appears in the lower right corner of the window.

You should then inspect the resulting files, either using IrfanView or another image previewer of your choice to ensure the compression levels aren’t too drastic on any of your images. If your files have dimensions of 600 x 800 pixels, they should be OK. However, if you’ve sized them at 824 x 1200 for the Kindle DX, you might see somewhat more compression artifacts, particularly in areas where there is a lot of flat white space. As long as the text on the images is legible, you can probably get away with slightly smaller images. I’ll be going into more detail about optimizing ebook images in future posts.

Next, you’ll either have to add these images to the ebook file you have under construction, or in my case, you’ll have to open the EPUB file you intend to convert to MOBI and replace the image files with these new ones. I did this using Calibre.

Drag and drop your EPUB file into Calibre, then right-click on the title and choose Tweak Book.

Calibre: Tweak Book
Calibre: Tweak Book

Then, in the window that opens, simply click the Explode Book button to open the contents of your ebook into a folder window.

Calibre: Explode Book
Calibre: Explode Book

In the folder window that appears, simply drill down into the OEBPS\Images folder, and replace the images there with the new ones you’ve converted – in my case I’ve simply selected all the files in my mobi-version-reduced folder, and dragged them into the Images folder in my exploded EPUB:

Copy and Replace
Copy and Replace

When your operating system asks you whether you want to replace the old files, indicate that you do. Important: your new images will need to have been named exactly in the same way as the old ones.

Close the exploded ebook folder window, and click the Rebuild Book button in Calibre to integrate all your new files into your ebook.

Calibre: Rebuild Book
Calibre: Rebuild Book

This post is more than long enough, so I won’t go into the MOBI conversion process (you can use Calibre or KindleGen), except to remind you that before you convert this EPUB to MOBI, you should check the new overall file size to make sure it is under 50 MB overall:

Ebook file size in Calibre
Ebook file size in Calibre

All is well!

2 Replies to “Tutorial: Saving Multiple Images to Target File Size for Kindle MOBI”

  1. You can do this in Photoshop CS6 and Photoshop CC:

    1. Create a new Action and name it e.g. JPEG_500KB
    2. Start Recording
    3. Use Save for Web
    4. Click on the small Optimize Menu icon (to the right of the Presets)
    5. Use Optimize to File Size and choose your target File Size e.g. 500Kb
    6. Click on the small Optimize Menu icon (to the right of the Presets)
    7. Choose Save Setting and give it a name e.g. JPEG_500KB
    8. Click on Save
    9. Close the original
    10. Stop recording the Action
    11. File > Automate > Batch
    12. Choose your Action e.g. JPEG_500KB and select your folder and options etc then run it

    This will then run through all your images and reduce them all to your required file size.

Comments are closed.