diff --git a/src/calibre/utils/magick/draw.py b/src/calibre/utils/magick/draw.py index c03a8660c8..ad4b681b43 100644 --- a/src/calibre/utils/magick/draw.py +++ b/src/calibre/utils/magick/draw.py @@ -92,7 +92,10 @@ def identify_data(data): or raises an Exception if data is not an image. ''' img = Image() - img.load(data) + if hasattr(img, 'identify'): + img.identify(data) + else: + img.load(data) width, height = img.size fmt = img.format return (width, height, fmt) diff --git a/src/calibre/utils/magick/magick.c b/src/calibre/utils/magick/magick.c index fd9563529a..869b77c736 100644 --- a/src/calibre/utils/magick/magick.c +++ b/src/calibre/utils/magick/magick.c @@ -456,6 +456,26 @@ magick_Image_load(magick_Image *self, PyObject *args, PyObject *kwargs) { // }}} +// Image.identify {{{ +static PyObject * +magick_Image_identify(magick_Image *self, PyObject *args, PyObject *kwargs) { + const char *data; + Py_ssize_t dlen; + MagickBooleanType res; + + NULL_CHECK(NULL) + if (!PyArg_ParseTuple(args, "s#", &data, &dlen)) return NULL; + + res = MagickPingImageBlob(self->wand, data, dlen); + + if (!res) + return magick_set_exception(self->wand); + + Py_RETURN_NONE; +} + +// }}} + // Image.open {{{ static PyObject * magick_Image_read(magick_Image *self, PyObject *args, PyObject *kwargs) { @@ -993,6 +1013,10 @@ static PyMethodDef magick_Image_methods[] = { {"destroy", (PyCFunction)magick_Image_destroy, METH_VARARGS, "Destroy the underlying ImageMagick Wand. WARNING: After using this method, all methods on this object will raise an exception."}, + {"identify", (PyCFunction)magick_Image_identify, METH_VARARGS, + "Identify an image from a byte buffer (string)" + }, + {"load", (PyCFunction)magick_Image_load, METH_VARARGS, "Load an image from a byte buffer (string)" },