02-11-2016, 07:46 AM | #1 |
Connoisseur
Posts: 58
Karma: 18990
Join Date: Jan 2016
Device: Kobo
|
How to get book cover width and height in Calibre Python code?
I am trying to write a template function that gives the width and height of the cover, when there is one. But I do not know the structure of Calibre well enough, and I have be unable to sort out the class definitions to find how to access that information (I am pretty much a beginner with calibre).
For example, I understand (I think) how the template function booksize() works, but I do not see how to do something similar for the cover size. Is there a map of the main classes used to represent books and metadata? Alternatively, given that I have a metadata instance MI for an ebook, how can I get in Python the width and height of the cover, as integers www and hhh or as a string 'wwwxhhh'. |
02-11-2016, 07:53 AM | #2 |
creator of calibre
Posts: 44,380
Karma: 23764838
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
The metadata object is documented in the template reference: http://manual.calibre-ebook.com/gene...tadata-objects
And the metadata object does not store cover dimensions. Indeed, cover dimensions are not stored in the calibre database at all. |
Advert | |
|
02-11-2016, 08:52 AM | #3 |
Connoisseur
Posts: 58
Karma: 18990
Join Date: Jan 2016
Device: Kobo
|
Thank you for the reply.
By playing with the code through ad hoc template functions, I concluded that the cover dimensions are probably not stored in Metadata objects, at least not directly. But I also know that the GUI for the metadata editor does display the cover, together with its width and height. So my guess is that there must be some way the cover can be accessed in some form (possibly a file) and its size computed. Am I being too naive? (BTW great work) |
02-11-2016, 09:55 AM | #4 |
creator of calibre
Posts: 44,380
Karma: 23764838
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
You only have access to information stored in the db in template functions. This is for performance reasons, templates are evaluated everytime you move around in the book list. Since cover dimensions are not stored in the db, trying to access them with a template is not a good idea. Instead I would suggest you create a plugin, that populates a custom column with the information when run.
|
Tags |
calibre, cover format, python, template |
Thread Tools | Search this Thread |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Calibre - changing the line-height in the user interface book description | CynthiaBlue | Development | 2 | 02-05-2016 12:48 AM |
Resizing images, retaining width-height rato, and only if necessary. | Vanguard3000 | Sigil | 7 | 07-31-2015 10:43 AM |
DOCX to MOBI Problems with Fixed Width Code Style | grepnick | Conversion | 13 | 02-03-2015 12:44 AM |
Flightcrew : is px for the height/width forbidden ? | NicolasR | Sigil | 2 | 02-11-2011 03:51 AM |
WIDTH and HEIGHT in <img> tags | Pablo | Sigil | 3 | 06-10-2010 05:37 PM |