From c650488bce88b105e25a8a3e3ef0cb2d0f3ff368 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 10 Oct 2010 12:56:48 -0600 Subject: [PATCH] RTF Input: Fix regression in conversion of WMF images on linux at least, maybe on other platforms as well --- src/calibre/utils/magick/__init__.py | 7 +++++++ src/calibre/utils/magick/magick.c | 22 ++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/calibre/utils/magick/__init__.py b/src/calibre/utils/magick/__init__.py index 3a4fca09c0..bf0f48db7d 100644 --- a/src/calibre/utils/magick/__init__.py +++ b/src/calibre/utils/magick/__init__.py @@ -109,6 +109,13 @@ class Image(_magick.Image): # {{{ return _magick.Image.load(self, bytes(data)) def open(self, path_or_file): + if not hasattr(path_or_file, 'read') and \ + path_or_file.lower().endswith('.wmf'): + # Special handling for WMF files as ImageMagick seems + # to hand while reading them from a blob on linux + if isinstance(path_or_file, unicode): + path_or_file = path_or_file.encode(filesystem_encoding) + return _magick.Image.read(self, path_or_file) data = path_or_file if hasattr(data, 'read'): data = data.read() diff --git a/src/calibre/utils/magick/magick.c b/src/calibre/utils/magick/magick.c index b1436a830b..0aab5f1fd7 100644 --- a/src/calibre/utils/magick/magick.c +++ b/src/calibre/utils/magick/magick.c @@ -414,6 +414,24 @@ magick_Image_load(magick_Image *self, PyObject *args, PyObject *kwargs) { // }}} +// Image.load {{{ +static PyObject * +magick_Image_read(magick_Image *self, PyObject *args, PyObject *kwargs) { + const char *data; + MagickBooleanType res; + + if (!PyArg_ParseTuple(args, "s", &data)) return NULL; + + res = MagickReadImage(self->wand, data); + + if (!res) + return magick_set_exception(self->wand); + + Py_RETURN_NONE; +} + +// }}} + // Image.create_canvas {{{ static PyObject * magick_Image_create_canvas(magick_Image *self, PyObject *args, PyObject *kwargs) @@ -873,6 +891,10 @@ static PyMethodDef magick_Image_methods[] = { "Load an image from a byte buffer (string)" }, + {"read", (PyCFunction)magick_Image_read, METH_VARARGS, + "Read image from path. Path must be a bytestring in the filesystem encoding" + }, + {"export", (PyCFunction)magick_Image_export, METH_VARARGS, "export(format) -> bytestring\n\n Export the image as the specified format" },