diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index f2c471a71f89..0f6cd2750ee8 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -327,6 +327,8 @@ def _draw_unsampled_image(self, renderer, gc): im.reset_matrix() numrows, numcols = im.get_size() + if numrows <= 0 or numcols <= 0: + return im.resize(numcols, numrows) # just to create im.bufOut that # is required by backends. There # may be better solution -JJL diff --git a/src/_image.cpp b/src/_image.cpp index b85cdf2af9f6..b1c59e9674ba 100644 --- a/src/_image.cpp +++ b/src/_image.cpp @@ -374,10 +374,10 @@ Image::resize(const Py::Tuple& args, const Py::Dict& kwargs) int numcols = Py::Int(args[0]); int numrows = Py::Int(args[1]); - if (numcols < 0 || numrows < 0) + if (numcols <= 0 || numrows <= 0) { - throw Py::RuntimeError( - "Width and height must have non-negative values"); + throw Py::RuntimeError( + "Width and height must have positive values"); } colsOut = numcols; diff --git a/src/_image.h b/src/_image.h index 425bc2462ff3..aa0de94174cd 100644 --- a/src/_image.h +++ b/src/_image.h @@ -45,6 +45,12 @@ class Image : public Py::PythonExtension inline Py::Object flipud_out(const Py::Tuple& args) { args.verify_length(0); + if (colsOut <= 0 || rowsOut <= 0) + { + throw Py::RuntimeError( + "Width and height must have positive values"); + } + int stride = rbufOut->stride(); //std::cout << "flip before: " << rbufOut->stride() << std::endl; rbufOut->attach(bufferOut, colsOut, rowsOut, -stride);