diff --git a/src/calibre/devices/cybookg3/driver.py b/src/calibre/devices/cybookg3/driver.py index e0caff36f8..cd9545f231 100644 --- a/src/calibre/devices/cybookg3/driver.py +++ b/src/calibre/devices/cybookg3/driver.py @@ -47,7 +47,7 @@ class CYBOOKG3(USBMS): DELETE_EXTS = ['.mbp', '.dat', '_6090.t2b'] SUPPORTS_SUB_DIRS = True - def upload_cover(self, path, name, coverdata): + def upload_cover(self, path, name, coverdata, metadata): with open('%s_6090.t2b' % os.path.join(path, name), 'wb') as t2bfile: t2b.write_t2b(t2bfile, coverdata) diff --git a/src/calibre/devices/nook/driver.py b/src/calibre/devices/nook/driver.py index c3f3267401..4cf65c866e 100644 --- a/src/calibre/devices/nook/driver.py +++ b/src/calibre/devices/nook/driver.py @@ -8,6 +8,14 @@ __docformat__ = 'restructuredtext en' Device driver for Barns and Nobel's Nook ''' +try: + from PIL import Image, ImageDraw + Image +except ImportError: + import Image + +import cStringIO + from calibre.devices.usbms.driver import USBMS class NOOK(USBMS): @@ -38,10 +46,24 @@ class NOOK(USBMS): EBOOK_DIR_MAIN = 'my documents' SUPPORTS_SUB_DIRS = True - def upload_cover(self, path, name, coverdata): - if coverdata: - with open('%s.jpg' % os.path.join(path, name), 'wb') as coverfile: - coverfile.write(coverdata) + def upload_cover(self, path, name, coverdata, metadata): + if not coverdata: + coverdata = open(I('library.png'), 'rb').read() + + im = Image.open(cStringIO.StringIO(coverdata)) + im.thumbnail((96, 144), Image.ANTIALIAS) + + if not coverdata: + draw = ImageDraw.Draw(im) + draw.text((0, 29), metadata.title) + draw.text((0, 115), ', '.join(metadata.authors)) + + data = cStringIO.StringIO() + im.save(data, 'JPG') + coverdata = data.getvalue() + + with open('%s.jpg' % os.path.join(path, name), 'wb') as coverfile: + coverfile.write(coverdata) def windows_sort_drives(self, drives): main = drives.get('main', None) diff --git a/src/calibre/devices/usbms/driver.py b/src/calibre/devices/usbms/driver.py index ee746de9cc..e37ea62525 100644 --- a/src/calibre/devices/usbms/driver.py +++ b/src/calibre/devices/usbms/driver.py @@ -115,7 +115,7 @@ class USBMS(CLI, Device): coverdata = mdata.get('cover', None) if coverdata: coverdata = coverdata[2] - self.upload_cover(os.path.dirname(filepath), os.path.splitext(os.path.basename(filepath))[0], coverdata) + self.upload_cover(os.path.dirname(filepath), os.path.splitext(os.path.basename(filepath))[0], coverdata, mdata) self.report_progress((i+1) / float(len(files)), _('Transferring books to device...'))