Add some texture to calibre generated covers

This commit is contained in:
Kovid Goyal 2012-06-26 19:30:20 +05:30
parent 303ec37090
commit 401aecc771
5 changed files with 54 additions and 4 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View File

@ -8,6 +8,7 @@ let g:syntastic_cpp_include_dirs = [
\'/usr/include/qt4/QtGui', \'/usr/include/qt4/QtGui',
\'/usr/include/qt4', \'/usr/include/qt4',
\'src/qtcurve/common', 'src/qtcurve', \'src/qtcurve/common', 'src/qtcurve',
\'/usr/include/ImageMagick',
\] \]
let g:syntastic_c_include_dirs = g:syntastic_cpp_include_dirs let g:syntastic_c_include_dirs = g:syntastic_cpp_include_dirs

View File

@ -187,7 +187,9 @@ def calibre_cover(title, author_string, series_string=None,
lines.append(TextLine(series_string, author_size)) lines.append(TextLine(series_string, author_size))
if logo_path is None: if logo_path is None:
logo_path = I('library.png') logo_path = I('library.png')
return create_cover_page(lines, logo_path, output_format='jpg') return create_cover_page(lines, logo_path, output_format='jpg',
texture_opacity=0.3, texture_data=I('cover_texture.png',
data=True))
UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc)$') UNIT_RE = re.compile(r'^(-*[0-9]*[.]?[0-9]*)\s*(%|em|ex|en|px|mm|cm|in|pt|pc)$')

View File

@ -245,12 +245,18 @@ class TextLine(object):
def create_cover_page(top_lines, logo_path, width=590, height=750, def create_cover_page(top_lines, logo_path, width=590, height=750,
bgcolor='#ffffff', output_format='jpg'): bgcolor='#ffffff', output_format='jpg', texture_data=None,
texture_opacity=1.0):
''' '''
Create the standard calibre cover page and return it as a byte string in Create the standard calibre cover page and return it as a byte string in
the specified output_format. the specified output_format.
''' '''
canvas = create_canvas(width, height, bgcolor) canvas = create_canvas(width, height, bgcolor)
if texture_data and hasattr(canvas, 'texture'):
texture = Image()
texture.load(texture_data)
texture.set_opacity(texture_opacity)
canvas.texture(texture)
bottom = 10 bottom = 10
for line in top_lines: for line in top_lines:
@ -263,7 +269,7 @@ def create_cover_page(top_lines, logo_path, width=590, height=750,
if not foot_font: if not foot_font:
foot_font = P('fonts/liberation/LiberationMono-Regular.ttf') foot_font = P('fonts/liberation/LiberationMono-Regular.ttf')
vanity = create_text_arc(__appname__ + ' ' + __version__, 24, vanity = create_text_arc(__appname__ + ' ' + __version__, 24,
font=foot_font) font=foot_font, bgcolor='#00000000')
lwidth, lheight = vanity.size lwidth, lheight = vanity.size
left = int(max(0, (width - lwidth)/2.)) left = int(max(0, (width - lwidth)/2.))
top = height - lheight - 10 top = height - lheight - 10

View File

@ -495,6 +495,7 @@ typedef struct {
// Method declarations {{{ // Method declarations {{{
static PyObject* magick_Image_compose(magick_Image *self, PyObject *args, PyObject *kwargs); static PyObject* magick_Image_compose(magick_Image *self, PyObject *args, PyObject *kwargs);
static PyObject* magick_Image_copy(magick_Image *self, PyObject *args, PyObject *kwargs); static PyObject* magick_Image_copy(magick_Image *self, PyObject *args, PyObject *kwargs);
static PyObject* magick_Image_texture(magick_Image *self, PyObject *args, PyObject *kwargs);
// }}} // }}}
static void static void
@ -926,7 +927,6 @@ magick_Image_flip(magick_Image *self, PyObject *args, PyObject *kwargs) {
} }
// }}} // }}}
// Image.set_page {{{ // Image.set_page {{{
static PyObject * static PyObject *
@ -1114,6 +1114,22 @@ magick_Image_destroy(magick_Image *self, PyObject *args, PyObject *kwargs) {
} }
// }}} // }}}
// Image.set_opacity {{{
static PyObject *
magick_Image_set_opacity(magick_Image *self, PyObject *args, PyObject *kwargs) {
double opacity;
NULL_CHECK(NULL)
if (!PyArg_ParseTuple(args, "d", &opacity)) return NULL;
if (!MagickSetImageOpacity(self->wand, opacity)) return magick_set_exception(self->wand);
Py_RETURN_NONE;
}
// }}}
// Image attr list {{{ // Image attr list {{{
static PyMethodDef magick_Image_methods[] = { static PyMethodDef magick_Image_methods[] = {
{"destroy", (PyCFunction)magick_Image_destroy, METH_VARARGS, {"destroy", (PyCFunction)magick_Image_destroy, METH_VARARGS,
@ -1145,6 +1161,14 @@ static PyMethodDef magick_Image_methods[] = {
"compose(img, left, top, op) \n\n Compose img using operation op at (left, top)" "compose(img, left, top, op) \n\n Compose img using operation op at (left, top)"
}, },
{"texture", (PyCFunction)magick_Image_texture, METH_VARARGS,
"texture(img)) \n\n Repeatedly tile img across and down the canvas."
},
{"set_opacity", (PyCFunction)magick_Image_set_opacity, METH_VARARGS,
"set_opacity(opacity)) \n\n Set the opacity of this image (between 0.0 - transparent and 1.0 - opaque)"
},
{"copy", (PyCFunction)magick_Image_copy, METH_VARARGS, {"copy", (PyCFunction)magick_Image_copy, METH_VARARGS,
"copy(img) \n\n Copy img to self." "copy(img) \n\n Copy img to self."
}, },
@ -1335,6 +1359,23 @@ magick_Image_copy(magick_Image *self, PyObject *args, PyObject *kwargs)
} }
// }}} // }}}
// Image.texture {{{
static PyObject *
magick_Image_texture(magick_Image *self, PyObject *args, PyObject *kwargs) {
PyObject *img;
magick_Image *texture;
NULL_CHECK(NULL)
if (!PyArg_ParseTuple(args, "O!", &magick_ImageType, &img)) return NULL;
texture = (magick_Image*)img;
if (!IsMagickWand(texture->wand)) {PyErr_SetString(PyExc_TypeError, "Not a valid ImageMagick wand"); return NULL;}
self->wand = MagickTextureImage(self->wand, texture->wand);
Py_RETURN_NONE;
}
// }}} // }}}
// Module functions {{{ // Module functions {{{