Skip to content

Commit f5f108d

Browse files
fix: Return first item from iso speed rating array (#7585)
1 parent 07c14e2 commit f5f108d

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Image/Exif.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Kirby\Image;
44

5+
use Kirby\Toolkit\A;
56
use Kirby\Toolkit\V;
67

78
/**
@@ -25,7 +26,7 @@ class Exif
2526
protected string|null $exposure = null;
2627
protected string|null $focalLength = null;
2728
protected bool|null $isColor = null;
28-
protected string|null $iso = null;
29+
protected array|string|null $iso = null;
2930
protected Location|null $location = null;
3031
protected string|null $timestamp = null;
3132
protected int $orientation;
@@ -96,6 +97,10 @@ public function aperture(): string|null
9697
*/
9798
public function iso(): string|null
9899
{
100+
if (is_array($this->iso) === true) {
101+
return A::first($this->iso);
102+
}
103+
99104
return $this->iso;
100105
}
101106

tests/Image/ExifTest.php

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@
88
#[CoversClass(Exif::class)]
99
class ExifTest extends TestCase
1010
{
11+
protected function _image($filename = 'image/cat.jpg')
12+
{
13+
return new Image(static::FIXTURES . '/' . $filename);
14+
}
15+
1116
protected function _exif($filename = 'image/cat.jpg')
1217
{
13-
$image = new Image(static::FIXTURES . '/' . $filename);
18+
$image = $this->_image($filename);
1419
return new Exif($image);
1520
}
1621

@@ -70,6 +75,38 @@ public function testAperture(): void
7075
}
7176

7277
public function testIso(): void
78+
{
79+
$image = $this->_image();
80+
$exif = new class ($image) extends Exif {
81+
public static function read(string $root): array
82+
{
83+
return [
84+
...parent::read($root),
85+
'ISOSpeedRatings' => 100
86+
];
87+
}
88+
};
89+
90+
$this->assertSame('100', $exif->iso());
91+
}
92+
93+
public function testIsoWithArrayValue(): void
94+
{
95+
$image = $this->_image();
96+
$exif = new class ($image) extends Exif {
97+
public static function read(string $root): array
98+
{
99+
return [
100+
...parent::read($root),
101+
'ISOSpeedRatings' => [100, 200]
102+
];
103+
}
104+
};
105+
106+
$this->assertSame('100', $exif->iso());
107+
}
108+
109+
public function testIsoWithoutValue(): void
73110
{
74111
$exif = $this->_exif();
75112
$this->assertNull($exif->iso());

0 commit comments

Comments
 (0)