From f15a30932c64fb87955e5db36433a5c3d2cfbf33 Mon Sep 17 00:00:00 2001 From: Oliver Vogel Date: Thu, 5 Oct 2023 17:54:19 +0200 Subject: [PATCH] Add tests for EXIF data reading --- .../Gd/Decoders/BinaryImageDecoderTest.php | 17 ++++++++++++++--- .../Decoders/BinaryImageDecoderTest.php | 17 ++++++++++++++--- tests/images/exif.jpg | Bin 0 -> 7791 bytes 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 tests/images/exif.jpg diff --git a/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php b/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php index 632f03634..f59f04961 100644 --- a/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php +++ b/tests/Drivers/Gd/Decoders/BinaryImageDecoderTest.php @@ -15,7 +15,7 @@ class BinaryImageDecoderTest extends TestCase public function testDecodePng(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/tile.png')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('tile.png'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->getWidth()); $this->assertEquals(16, $image->getHeight()); @@ -25,7 +25,7 @@ public function testDecodePng(): void public function testDecodeGif(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/red.gif')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('red.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->getWidth()); $this->assertEquals(16, $image->getHeight()); @@ -35,10 +35,21 @@ public function testDecodeGif(): void public function testDecodeAnimatedGif(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/cats.gif')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('cats.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(75, $image->getWidth()); $this->assertEquals(50, $image->getHeight()); $this->assertCount(4, $image); } + + public function testDecodeJpegWithExif(): void + { + $decoder = new BinaryImageDecoder(); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('exif.jpg'))); + $this->assertInstanceOf(Image::class, $image); + $this->assertEquals(16, $image->getWidth()); + $this->assertEquals(16, $image->getHeight()); + $this->assertCount(1, $image); + $this->assertEquals('Oliver Vogel', $image->getExif('IFD0.Artist')); + } } diff --git a/tests/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php b/tests/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php index 455bdcc7b..b3d20b4a5 100644 --- a/tests/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php +++ b/tests/Drivers/Imagick/Decoders/BinaryImageDecoderTest.php @@ -11,7 +11,7 @@ class BinaryImageDecoderTest extends TestCase public function testDecodePng(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/tile.png')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('tile.png'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->getWidth()); $this->assertEquals(16, $image->getHeight()); @@ -21,7 +21,7 @@ public function testDecodePng(): void public function testDecodeGif(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/red.gif')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('red.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(16, $image->getWidth()); $this->assertEquals(16, $image->getHeight()); @@ -31,10 +31,21 @@ public function testDecodeGif(): void public function testDecodeAnimatedGif(): void { $decoder = new BinaryImageDecoder(); - $image = $decoder->decode(file_get_contents(__DIR__ . '/../../../images/cats.gif')); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('cats.gif'))); $this->assertInstanceOf(Image::class, $image); $this->assertEquals(75, $image->getWidth()); $this->assertEquals(50, $image->getHeight()); $this->assertCount(4, $image); } + + public function testDecodeJpegWithExif(): void + { + $decoder = new BinaryImageDecoder(); + $image = $decoder->decode(file_get_contents($this->getTestImagePath('exif.jpg'))); + $this->assertInstanceOf(Image::class, $image); + $this->assertEquals(16, $image->getWidth()); + $this->assertEquals(16, $image->getHeight()); + $this->assertCount(1, $image); + $this->assertEquals('Oliver Vogel', $image->getExif('IFD0.Artist')); + } } diff --git a/tests/images/exif.jpg b/tests/images/exif.jpg new file mode 100644 index 0000000000000000000000000000000000000000..ab98706c205e3054afaf64359c11890fb3d45214 GIT binary patch literal 7791 zcmeGhTW}lI_3o}-mSjhYZDIn$EXteK*2`9Gfk`acu}!1Ik>tF7I;-84ykxbj?5=Dj z9~}sxw9Irm389p9h9LoPzvopn-FN}V@5squ689k=24h_ z)z{wpIOp7R&pCVU*?V>BFVrtE(nL)vB9zIXn-D@Cpl0HHTb)DUx zr#3cdXrPHAs1Xa#r>Gd|_dx$4>SogKg#OukB;wDw7?Wf)?vW+WHIi zH;|ub^vQGvQT4x|E;2&G9hk2E8*~);JswYo$KTQ65Bj{mVDAdQe?@O!cXw}hcVEy? zN~19ci)*UW=j-h140Lq`db+y0dT`a%V@?Tv5C-+9P|$+{D8Nu5LcS_ zsVyL-lOhEK#)Ux??Qpu>o(``M9HSjcA)2v}0Yo_{hIY_Sx69*X{Bb}A8OMz)qt3Bi zTzBZ;oiSI>u~Uzy)~xN#K3#|pYDb<+yVo7hUAl0Y*N3h-efF;PEMyPv%O*7QRijchV2F1zn$eA1K~-f!F|8P)s8q`s zf%~{k%Nic9Aaiq44O65f1JA)|lc%Wd;L2itVs9Qm=3?fA8BJA-Ink(Ab{1~u0qI9G zNJA?86%mVaNJIvzq6%h(ycL@oMubgDHk5`${z6rf4M`y^0pCHW)0usrFfDg8WkR}95c0+cLh_8?o*Gxi{@De2}wF`9$z1zEQ-J4(j9J(wuV z!l4ZUwjL3paDb+C4vaBkl#uUGW z!6LN4J1uxtD$TVbd=>&^v+40(VcsxhXoPLrYRNuYPjFq0MWNYp2QvMwlfdwPtr5y= z?ePtS>lHHYAT?AJnFXIXT)d4<0uD=P-zLy06fPD4BSQ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