File tree Expand file tree Collapse file tree 5 files changed +34
-2
lines changed
Expand file tree Collapse file tree 5 files changed +34
-2
lines changed Original file line number Diff line number Diff line change 1313
1414use PHPExif \Exif ;
1515use Imagick ;
16+ use Safe \Exceptions \ImageException ;
1617
1718use function Safe \filesize ;
1819use function Safe \iptcparse ;
@@ -105,7 +106,11 @@ public function getExifFromFile(string $file) : Exif
105106 public function getIptcData (string $ profile ) : array
106107 {
107108 $ arrData = [];
108- $ iptc = iptcparse ($ profile );
109+ try {
110+ $ iptc = iptcparse ($ profile );
111+ } catch (ImageException ) {
112+ return $ arrData ;
113+ }
109114
110115 foreach ($ this ->iptcMapping as $ name => $ field ) {
111116 if (!isset ($ iptc [$ field ])) {
Original file line number Diff line number Diff line change @@ -258,7 +258,11 @@ public function getIptcData(string $file) : array
258258 getimagesize ($ file , $ info );
259259 $ arrData = array ();
260260 if (isset ($ info ['APP13 ' ])) {
261- $ iptc = iptcparse ($ info ['APP13 ' ]);
261+ try {
262+ $ iptc = iptcparse ($ info ['APP13 ' ]);
263+ } catch (ImageException ) {
264+ return $ arrData ;
265+ }
262266
263267 foreach ($ this ->iptcMapping as $ name => $ field ) {
264268 if (!isset ($ iptc [$ field ])) {
Original file line number Diff line number Diff line change @@ -27,4 +27,15 @@ public function testGetExifFromFile()
2727 $ this ->assertNotEmpty ($ result ->getRawData ());
2828 }
2929
30+ /**
31+ * @group ImageMagick
32+ * @covers \PHPExif\Adapter\ImageMagick::getIptcData
33+ */
34+ public function testGetEmptyIptcData ()
35+ {
36+ $ result = $ this ->adapter ->getIptcData ("" );
37+
38+ $ this ->assertEquals ([], $ result );
39+ }
40+
3041}
Original file line number Diff line number Diff line change @@ -145,6 +145,18 @@ public function testGetIptcData()
145145 $ this ->assertEquals ($ expected , $ result );
146146 }
147147
148+ /**
149+ * @group native
150+ * @covers \PHPExif\Adapter\Native::getIptcData
151+ */
152+ public function testGetEmptyIptcData ()
153+ {
154+ $ file = PHPEXIF_TEST_ROOT . '/files/empty_iptc.jpg ' ;
155+ $ result = $ this ->adapter ->getIptcData ($ file );
156+
157+ $ this ->assertEquals ([], $ result );
158+ }
159+
148160 /**
149161 * @group native
150162 * @covers \PHPExif\Adapter\Native::setSectionsAsArrays
You can’t perform that action at this time.
0 commit comments