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

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 03-08-2011, 07:49 AM   #1
chewi
Member
chewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-books
 
chewi's Avatar
 
Posts: 14
Karma: 822
Join Date: Nov 2010
Device: sony prs-650
Question Adding date (and maybe other info) to custom cover image

When using the default cover image, the name of newspaper/magazine and the date are automatically added over it:



Is it possible (by placing some code in recipe) to add the date or any other info over the custom cover image?
chewi is offline   Reply With Quote
Old 03-08-2011, 10:13 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: 43,826
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Override the default_cover method in your recipe
kovidgoyal is offline   Reply With Quote
Advert
Old 03-08-2011, 11:32 AM   #3
chewi
Member
chewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-books
 
chewi's Avatar
 
Posts: 14
Karma: 822
Join Date: Nov 2010
Device: sony prs-650
Question

As I understand, this code is sample

Spoiler:
def default_cover(self, cover_file):
'''
Create a generic cover for recipes that dont have a cover
'''
try:
from calibre.ebooks import calibre_cover
title = self.title if isinstance(self.title, unicode) else \
self.title.decode(preferred_encoding, 'replace')
date = strftime(self.timefmt)
img_data = calibre_cover(title, date)
cover_file.write(img_data)
cover_file.flush()
except:
self.log.exception('Failed to generate default cover')
return False
return True


I want:
- use cover image from url 'http://pics.rbc.ru/img/top/2002/04/26/rbc-logo.gif'
- add borders like command cover_margins = (200, 300, '#ffffff') do
- add title and date to the resulting cover

Can you help with the code for all this steps?
chewi is offline   Reply With Quote
Old 03-08-2011, 04:22 PM   #4
joeindallas
Enthusiast
joeindallas began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Jan 2011
Device: Kindle 3
I would like to be able to do that as well - is there a good example in the recipes directory of a custom cover from a url that adds a date and/or a time stamp to the cover image?

I tried doing a search and couldn't find any - probably not searching for the right terms.

Thanks
joeindallas is offline   Reply With Quote
Old 03-10-2011, 12:26 PM   #5
joeindallas
Enthusiast
joeindallas began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Jan 2011
Device: Kindle 3
chewi,

If you're still looking at this, I got my custom cover to work in a limited way. I used the nation_ke recipe (my recipe collects sports feeds from Dallas teams). The only trouble I had is that I wanted to use a "taller image, but when I deviated from the size of the image they used (597 x 85) my image was auto-shrunk and looked bad. Anyway - hope this helps:

Spoiler:
import os
from calibre import strftime, __appname__, __version__
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.constants import preferred_encoding
from calibre.utils.magick import Image

class AdvancedUserRecipe1295487944(BasicNewsRecipe):


__author__ = 'Joe Dworsky'

title = u'DMN Pro Sports Blogs'
description = 'News from Rangers, Mavericks, and Cowboys'
oldest_article = 7
max_articles_per_feed = 100
language = 'en'
country = 'US'
publication_type = 'newspaper'
publisher = 'none'
category = 'news, sports'
# cover_img_url = 'http://www.nation.co.ke/image/view/-/465228/medRes/33884/-/maxh/85/-/12e8pptz/-/Sunday_Logo.gif'
cover_img_url = 'http://img854.imageshack.us/img854/5519/3x85.jpg'
masthead_url = cover_img_url



no_stylesheets = True
extra_css = '''
h1{text-align:left;font-family:Arial,Helvetica,sans-serif; font-weight:bold;font-size:large;}
h2{text-align:left;font-family:Arial,Helvetica,sans-serif; font-weight:normal;font-size:small;}
p{text-align:left;font-family:Arial,Helvetica,sans-serif;font-size:small;}
body{text-align:left;font-family:Helvetica,Arial,sans-serif;font-size:small;}
'''

remove_tags = [dict(name='div', attrs={'class':'categoryGroup'})]
remove_tags.append(dict(name = 'div', attrs = {'class': 'archivesGroup'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'commentbox'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'cgmtitle'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'navigation breadcrumb'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'top-links'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'entry-footer'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'blog-body-heading'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'DMNContentModuleHdr'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'DMNContentModuleHdr1'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'slcgm_metadata cgminfo'}))
remove_tags.append(dict(name = 'div', attrs = {'class': 'groupHeadline-spt'}))
remove_tags.append(dict(name='img'))
remove_tags.append(dict(name = 'div', attrs = {'class': 'comments'}))

feeds = [(u'Rangers RSS', u'http://rangersblog.dallasnews.com/index.xml'), (u'Mavericks RSS', u'http://mavsblog.dallasnews.com/index.xml'), (u'Cowboys RSS', u'http://cowboysblog.dallasnews.com/index.xml')]

def get_cover_img_url(self):
return getattr(self, 'cover_img_url', None)

def _download_cover_img(self):
# hack to reuse download_cover
old_cu = None
try:
old_cu = self.get_cover_url()
except:
pass
new_cu = self.get_cover_img_url()
self.cover_url = new_cu
self._download_cover()

outfile = os.path.join(self.output_dir, 'cover_img.jpg')
self.prepare_masthead_image(self.cover_path, outfile)

self.cover_url = old_cu
self.cover_img_path = outfile

def download_cover_img(self):
try:
self._download_cover_img()
self.report_progress(1, _('Downloaded cover to %s') % self.cover_img_path)
except:
self.log.exception('Failed to download cover img')
self.cover_img_path = None

def prepare_cover_image(self, path_to_image, out_path):
img = Image()
img.open(path_to_image)
img.save(out_path)

def default_cover(self, cover_file):
'''
Create a generic cover for recipes that have a special cover img
'''
try:
try:
from PIL import Image, ImageDraw, ImageFont
Image, ImageDraw, ImageFont
except ImportError:
import Image, ImageDraw, ImageFont
font_path = P('fonts/liberation/LiberationSerif-Bold.ttf')
title = self.title if isinstance(self.title, unicode) else \
self.title.decode(preferred_encoding, 'replace')
date = strftime(self.timefmt)
app = '['+__appname__ +' '+__version__+']'

COVER_WIDTH, COVER_HEIGHT = 590, 750
img = Image.new('RGB', (COVER_WIDTH, COVER_HEIGHT), 'white')
draw = ImageDraw.Draw(img)
# Title
font = ImageFont.truetype(font_path, 44)
width, height = draw.textsize(title, font=font)
left = max(int((COVER_WIDTH - width)/2.), 0)
top = 15
draw.text((left, top), title, fill=(0,0,0), font=font)
bottom = top + height
# Date
font = ImageFont.truetype(font_path, 32)
width, height = draw.textsize(date, font=font)
left = max(int((COVER_WIDTH - width)/2.), 0)
draw.text((left, bottom+15), date, fill=(0,0,0), font=font)
# Vanity
font = ImageFont.truetype(font_path, 28)
width, height = draw.textsize(app, font=font)
left = max(int((COVER_WIDTH - width)/2.), 0)
top = COVER_HEIGHT - height - 15
draw.text((left, top), app, fill=(0,0,0), font=font)

# Logo
logo_file = I('library.png')
self.download_cover_img()
if getattr(self, 'cover_img_path', None) is not None:
logo_file = self.cover_img_path
self.report_progress(1, _('using cover img from %s') % logo_file)
logo = Image.open(logo_file, 'r')
width, height = logo.size
# left = max(int((COVER_WIDTH - width)/2.), 0)
# top = max(int((COVER_HEIGHT - height)/2.), 0)
left = max(10, 0)
top = max(150, 0)
img.paste(logo, (left, top))
img = img.convert('RGB').convert('P', palette=Image.ADAPTIVE)
img.convert('RGB').save(cover_file, 'JPEG')
cover_file.flush()
except Exception, e:
self.log.exception('Failed to generate default cover ', e)
return False
return True

joeindallas is offline   Reply With Quote
Advert
Old 03-14-2011, 10:23 AM   #6
chewi
Member
chewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-books
 
chewi's Avatar
 
Posts: 14
Karma: 822
Join Date: Nov 2010
Device: sony prs-650
joeindallas,

Thanx, but unfortunetely it doesn't work for me, default calibre cover appears.
chewi is offline   Reply With Quote
Old 03-14-2011, 05:20 PM   #7
joeindallas
Enthusiast
joeindallas began at the beginning.
 
Posts: 30
Karma: 10
Join Date: Jan 2011
Device: Kindle 3
Are you running the sample I posted and get the default image, or did you try to adapt it for your use? If the latter, can you post it here? I'm probably the least qualified here to help, but I have been playing with this lately.
joeindallas is offline   Reply With Quote
Old 03-16-2011, 04:21 AM   #8
chewi
Member
chewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-bookschewi has learned how to read e-books
 
chewi's Avatar
 
Posts: 14
Karma: 822
Join Date: Nov 2010
Device: sony prs-650
joeindallas,

Can you post here the above /Rangers RSS/ as attached .recipe file?
chewi is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding cover image miwie Library Management 9 03-04-2011 10:39 AM
PRS-300 Pictures: Pink 300 + Sony red cover + custom cover h0bbes Sony Reader 5 01-04-2010 12:41 PM
Date in Calibre? Adding books in the future? wygit Calibre 2 11-04-2009 11:12 AM
Adding cover image to PDF? silvijakk Bookeen 2 04-02-2009 03:33 PM
Adding a cover image to mobipocket files rheostaticsfan Kindle Formats 4 05-25-2008 03:40 PM


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


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