mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
ImageMagick: When identifying an image don't read the whole image
This commit is contained in:
parent
9518dcef80
commit
3e9e655674
@ -92,6 +92,9 @@ def identify_data(data):
|
||||
or raises an Exception if data is not an image.
|
||||
'''
|
||||
img = Image()
|
||||
if hasattr(img, 'identify'):
|
||||
img.identify(data)
|
||||
else:
|
||||
img.load(data)
|
||||
width, height = img.size
|
||||
fmt = img.format
|
||||
|
@ -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)"
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user