RTF Input: Fix regression in conversion of WMF images on linux at least, maybe on other platforms as well

This commit is contained in:
Kovid Goyal 2010-10-10 12:56:48 -06:00
parent 0030630453
commit c650488bce
2 changed files with 29 additions and 0 deletions

View File

@ -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()

View File

@ -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"
},