# How can I extract all the pictures from an ebook?

I read most of my books in txt format. I use Calibre to convert them to that format. While it works great for books that are mostly text, some ebooks which contain pictures can be very confusing when the pictures are removed. Is there some way to either:

1. Take all the images from a book and save them into one folder without having to copy each picture one at a time, or
2. Screenshot each page of the book with a program (again, I don't want to have to do this manually)?

If it could be done in bulk for many books, and with a Calibre plugin, that would be even better.

Any non-DRM'ed epub ebook is just a renamed zipped folder. All you'll need to do is rename the file from <filename>.epub to <filename>.zip and unzip the folder. At that point, you should be able to navigate within the folders to find the images and do whatever you like with them.

Hope that helps!

• I found this very useful. I'm on Ubuntu, so I just open the epub with Archive Manager. Is there any way to perhaps do this in bulk, or to maybe insert the names of the pictures in the converted ebook? (So I know which one is referred to? Thanks. – ike May 16 '14 at 2:43

You cannot do this in bulk without some programming. As @Tom indicated, .epub files are ZIP files. The extensions of the "file names" in the ZIP files for images are often, but not guaranteed to be '.jpg,.pngor.gif. But extracting these using:

unzip abc.epub *.jpg *.png *.gif


will have you miss any that have the extension .jpeg, .JPEG, .Png.

Because of the practically unlimited range of possible extensions for images referred to in the text of your ebook, they can only reliable be identified by one of the following methods:

1. analysing the (HTML) text
2. checking the headers of all the files included¹

The analysis being the better tool, as there might be (image) files in a (badly formatted) ebook that are never referenced/displayed². This however requires you to parse the XML/HTML to find the names of the files referenced in the <IMG> tags.

If your ebooks are programmatically generated, they might include (non-necessary) regularities in the image file naming, so that the above unzip command does work for your case. If that is so a simple script walking over your ebook library file structure and unzipping every ebook in an 'Images' subdirectory would suffice.

¹ There are only very, very few filenames pre-specified for .epub. ebooks, so you might as well check all the files.
² I once analysed an .epub, that looked too large for its contents. For some reason it included parts of the Christian mythology texts, which could not be displayed with a normal reader.

• With bash (which is Ubuntu's default shell, which is the distro the questioner is using), you could use shopt -s nocaseglob followed by your unzip command. It still wouldn't catch things like *.jpeg` or more irregular file extensions, but it would deal with case sensitivity problems. – evilsoup May 17 '14 at 10:11