diff --git a/resources/images/cover_texture.png b/resources/images/cover_texture.png new file mode 100644 index 0000000000..3fbc804ea8 Binary files /dev/null and b/resources/images/cover_texture.png differ diff --git a/session.vim b/session.vim index fbb573e27e..ae2c55bf06 100644 --- a/session.vim +++ b/session.vim @@ -8,6 +8,7 @@ let g:syntastic_cpp_include_dirs = [ \'/usr/include/qt4/QtGui', \'/usr/include/qt4', \'src/qtcurve/common', 'src/qtcurve', + \'/usr/include/ImageMagick', \] let g:syntastic_c_include_dirs = g:syntastic_cpp_include_dirs diff --git a/src/calibre/ebooks/__init__.py b/src/calibre/ebooks/__init__.py index 09cc2fbaaf..7a61c7cd96 100644 --- a/src/calibre/ebooks/__init__.py +++ b/src/calibre/ebooks/__init__.py @@ -187,7 +187,9 @@ def calibre_cover(title, author_string, series_string=None, lines.append(TextLine(series_string, author_size)) if logo_path is None: 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)$') diff --git a/src/calibre/utils/magick/draw.py b/src/calibre/utils/magick/draw.py index 0bfc806d42..046d0d5224 100644 --- a/src/calibre/utils/magick/draw.py +++ b/src/calibre/utils/magick/draw.py @@ -245,12 +245,18 @@ class TextLine(object): 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 the specified output_format. ''' 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 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: foot_font = P('fonts/liberation/LiberationMono-Regular.ttf') vanity = create_text_arc(__appname__ + ' ' + __version__, 24, - font=foot_font) + font=foot_font, bgcolor='#00000000') lwidth, lheight = vanity.size left = int(max(0, (width - lwidth)/2.)) top = height - lheight - 10 diff --git a/src/calibre/utils/magick/magick.c b/src/calibre/utils/magick/magick.c index e14c966282..4b336a2531 100644 --- a/src/calibre/utils/magick/magick.c +++ b/src/calibre/utils/magick/magick.c @@ -495,6 +495,7 @@ typedef struct { // Method declarations {{{ 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_texture(magick_Image *self, PyObject *args, PyObject *kwargs); // }}} static void @@ -926,7 +927,6 @@ magick_Image_flip(magick_Image *self, PyObject *args, PyObject *kwargs) { } // }}} - // Image.set_page {{{ 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 {{{ static PyMethodDef magick_Image_methods[] = { {"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)" }, + {"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(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 {{{