View Single Post
Old 03-30-2024, 08:23 AM   #3
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,475
Karma: 8025702
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Directly answering the question ...

In the past you haven't seemed interested in solutions involving composite columns and templates, but just in case I am wrong, here is one. It returns the width and height of the cover image. Performance isn't excellent because it must read the actual cover file off the disk. I suggest that if you use it then you display the results in book details and not in the book list making performance much less of an issue.

You would put this in a "Column built from other columns" with "Show as html" unchecked. You could check "Show in Tag browser" but it isn't obvious why you would want this.
Code:
python:
def evaluate(book, context):
	from io import BytesIO
	from PIL import Image
	mi = context.db.new_api.get_metadata(book.id, get_cover=True, cover_as_data=True)
	if mi.cover_data[1] is not None:
		pm = Image.open(BytesIO(mi.cover_data[1]))
		ans = f'w={str(pm.width)}, h={str(pm.height)}'
	else:
		ans = 'No cover'
	return ans
Attached Thumbnails
Click image for larger version

Name:	Clipboard01.jpg
Views:	248
Size:	69.0 KB
ID:	207243  

Last edited by chaley; 03-30-2024 at 08:25 AM. Reason: Added screen capture showing the output
chaley is offline   Reply With Quote