diff --git a/src/Image.php b/src/Image.php index a700894d..355dab0d 100644 --- a/src/Image.php +++ b/src/Image.php @@ -102,7 +102,7 @@ public function setLaserpointsAttribute($value) */ public function getAreaAttribute() { - return $this->accessLaserpointsArray('area'); + return $this->accessLaserpointsArray('area') ?: ($this->metadata['area'] ?? null); } /** diff --git a/tests/ImageTest.php b/tests/ImageTest.php index cc668166..5eefd8a5 100644 --- a/tests/ImageTest.php +++ b/tests/ImageTest.php @@ -54,6 +54,26 @@ public function testLaserpoints() $this->assertEquals($expect, $image->fresh()->laserpoints); } + public function testAreaAttribute() + { + $image = Image::convert(BaseImageTest::create()); + $this->assertNull($image->area); + + $image->metadata = [ + 'area' => 600, + ]; + $image->save(); + $this->assertEquals(600, $image->fresh()->area); + + // Laser point detection overrides the metadata. + $image->laserpoints = [ + 'area' => 500, + ]; + $image->save(); + + $this->assertEquals(500, $image->fresh()->area); + } + public function testLaserpointsNotThere() { $image = Image::convert(BaseImageTest::create(['attrs' => ['something' => 'else']]));