![]() |
#1 |
Nameless Being
|
How to add the cover to HTML and CBZ sources (the recipe)
I create my own books in calibre using HTML source files. The HTML format using the CSS styles is very flexible and very convenient in usage. Unfortunately calibre ignores the META tag pointing the cover file. It’s possible to insert at the beginning of the HTML source file the IMG tag that points the cover. In such a case calibre inserts that image at the beginning of the book but it doesn’t recognize it as a cover. As a result when there are a few images in the book calibre sets as a cover a random image from that collection and when the resulting book is in EPUB format calibre adds the default cover before the cover pointed by the IMG tag. (It’s easy to disable the default cover in the last case but it doesn’t matter because after that disabling the cover pointed by the IMG tag still isn’t recognized as a cover.)
The other problem is with CBZ source files (comic books). If the source file includes the cover as the first page calibre extracts that page from the source and renames it to cover.jpg. After the conversion of such a comic book the output includes doubled cover page: the cover page added by calibre and the other cover which was the first page of the source file. If the source file doesn’t include the cover calibre extracts the first page of the source, renames it to cover.jpg, and treats it as the cover of the comic book. The resulting book has doubled first page. I invented the simple method to add the book cover to the source using HTML or CBZ format. It should work with the other formats too though I didn’t test that. Unfortunately I don’t know Python at all and the calibre sources are too complicated for me so I can’t implement that feature in calibre. I spent a few hours on the futile attempts. For someone who is familiar with the structure of the calibre sources, who understands the calibre variables, and who knows Python it’ll be enough a few minutes to implement that feature. Let’s assume there’s source HTML file named szymborska.html in “~/Calibre Library/szymborska/poems/” source directory. The szymborska.html file includes TITLE tag equal “Three Poems” and AUTHOR META tag equal “Wisława Szymborska”. There isn’t IMG tag at the beginning of the szymborska.html file that points the cover. In the same directory there’s the cover file named cover.jpg. In such a case when one adds that book to calibre the program creates “~/Calibre Library/Wislawa Szymborska/Three Poems (123)/” destination directory and puts there two files: “Three Poems – Wislawa Szymborska.zip” and metadata.opf. What is lacking here it’s the cover.jpg file from the mentioned above source directory. If one copies that file to the destination directory manually and then she starts the conversion of the book calibre will insert the cover at the beginning of the book recognizing it as a cover. To copy the cover.jpg file from the source directory to the destination directory manually isn’t convenient. It would be great to implement that simple step into calibre. The similar case is with the comic book. Let’s assume the source directory includes the CBZ file without the cover and the separate cover.jpg file. During adding of the book calibre extracts the first page of the comic book and renames it to cover.jpg. It would be enough to overwrite that file with the cover.jpg file from the source directory to get the valid comic book after the conversion. There are two conditions: 1. The source HTML file hasn’t the IMG tag pointing the cover file and the source CBZ file hasn’t the cover as the first page. 2. In the directory that includes the source HTML file or the source CBZ file there’s the cover file named cover.jpg. The calibre should copy the cover.jpg file from the source directory to the destination directory when it adds the book. It should do that as the last step of adding the book in order to overwrite possible unwanted cover.jpg file generated by calibre. As a result the program will recognize that file as the cover during the conversion of the book. As I suppose it would be enough to add the following procedure to the calibre sources: Code:
import os, os.path, shutil cover_input = os.path.join(input_path, 'cover.jpg') cover_output = os.path.join(output_path, 'cover.jpg') if os.path.isfile(cover_input): shutil.copyfile(cover_input, cover_output) If you know how to implement such a feature in calibre but you think calibre is better without that feature let me know how I can implement it in my calibre installation. |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Merging two news sources in same recipe | cartesio | Calibre | 3 | 02-05-2012 04:05 PM |
Is it possible to add PDF to CBR/CBZ conversion | usualsuspect | Conversion | 0 | 05-07-2011 06:22 AM |
spiegelde.recipe: add cover | miwie | Recipes | 0 | 11-20-2010 08:58 AM |
How to add my own html page to recipe | naisren | Recipes | 3 | 11-17-2010 04:37 PM |
Calibre Recipe HTML content differs from raw html of index.html. | krunk | Calibre | 4 | 09-20-2010 09:48 PM |