Skip to content

Commit

Permalink
Merge pull request #67 from biigle/patch-1
Browse files Browse the repository at this point in the history
Fix image area attribute if the area was uploaded as metadata
  • Loading branch information
mzur authored Dec 6, 2023
2 parents eff6e3d + d74a7b7 commit 97d577a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function setLaserpointsAttribute($value)
*/
public function getAreaAttribute()
{
return $this->accessLaserpointsArray('area');
return $this->accessLaserpointsArray('area') ?: ($this->metadata['area'] ?? null);
}

/**
Expand Down
20 changes: 20 additions & 0 deletions tests/ImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']]));
Expand Down

0 comments on commit 97d577a

Please sign in to comment.