diff --git a/lib/private/image.php b/lib/private/image.php index 317b6fde1605..2484aeecc63f 100644 --- a/lib/private/image.php +++ b/lib/private/image.php @@ -283,9 +283,12 @@ public function resource() { } /** - * @return string Returns the raw image data. + * @return null|string Returns the raw image data. */ function data() { + if (!$this->valid()) { + return null; + } ob_start(); switch ($this->mimeType) { case "image/png": diff --git a/tests/lib/image.php b/tests/lib/image.php index e0009b9710eb..0ee517100ad5 100644 --- a/tests/lib/image.php +++ b/tests/lib/image.php @@ -144,6 +144,11 @@ public function testData() { $this->assertEquals($expected, $img->data()); } + public function testDataNoResource() { + $img = new \OC_Image(); + $this->assertNull($img->data()); + } + /** * @depends testData */