Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 02-11-2016, 08:46 AM   #1
datcha
Connoisseur
datcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic something
 
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'.
datcha is offline   Reply With Quote
Old 02-11-2016, 08:53 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 36,093
Karma: 15014853
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.
kovidgoyal is offline   Reply With Quote
Old 02-11-2016, 09:52 AM   #3
datcha
Connoisseur
datcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic somethingdatcha has a certain pleonastic something
 
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)
datcha is offline   Reply With Quote
Old 02-11-2016, 10:55 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 36,093
Karma: 15014853
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.
kovidgoyal is offline   Reply With Quote
Reply

Tags
calibre, cover format, python, template

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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 01:48 AM
Resizing images, retaining width-height rato, and only if necessary. Vanguard3000 Sigil 7 07-31-2015 11:43 AM
DOCX to MOBI Problems with Fixed Width Code Style grepnick Conversion 13 02-03-2015 01:44 AM
Flightcrew : is px for the height/width forbidden ? NicolasR Sigil 2 02-11-2011 04:51 AM
WIDTH and HEIGHT in <img> tags Pablo Sigil 3 06-10-2010 06:37 PM


All times are GMT -4. The time now is 11:11 AM.


MobileRead.com is a privately owned, operated and funded community.