Friday, October 24, 2025
HomeLanguagesPHP iptcparse() Function

PHP iptcparse() Function

What is IPTC data?

IPTC data is generally referred to as the metadata associated with an image file etc. It is the standardized metadata format created for the use of media. This IPTC data generally includes image details like location, description, title, date, and copyright.

The PHP iptcparse() function is an inbuilt function to parse this IPTC data from the image.

Syntax:

array|false iptcparse( string $iptc_data )

 

Parameters: This function accepts single parameter as mentioned above and described below:

  • $iptc_data: It takes a binary block of IPTC data that we fetched from the image.

Return value: On error or if data is found in the image then it returns a bool value false. If data is found in the image then it returns an array with a tag marker as an index.

Example 1: The following code is for an image when data is present in it.

PHP




<?php
  
// Fetching image size but we actually have to
// use $info that contain meta data of image
// 1st argument is name of the image and second
// is optional but we pass any variable name 
// because it contains meta data 
$img_size = getimagesize('1.jpg', $img_info);
  
/* We have an array of length three of meta
data of image in $img_info variable but we
have to parse only IPTC data so we have to
pass APP13 which contain IPTC data */
$iptc_data = iptcparse($img_info['APP13']);
  
// IPTC data fetched 
foreach ($iptc_data as $key => $value) {
    echo var_dump($key,"---",$value)."<br>";
}
  
echo "<br><b>Fetching data:</b><br>";
  
// Now looping through each and every
// key value pair
foreach ($iptc_data as $key => $value) {
    for ($i=0; $i < sizeof($value); $i++) { 
        echo $key." -- ".$value[$i]."<br>";
    }
}
  
?>


Output: We can see these keys that represents –

2#120 — Title of the image

2#080 — Author of the images

2#055 — Date of image when it is created 

2#060 — Time 

2#025 — Tags in an image 

2#116 — Copyright of Image

string(5) “1#090” string(3) “—” array(1) { [0]=> string(3) “%G” }
string(5) “1#000” string(3) “—” array(1) { [0]=> string(2) “” }
string(5) “2#000” string(3) “—” array(1) { [0]=> string(2) “” }
string(5) “2#120” string(3) “—” array(1) { [0]=> string(91) “Front part views of
three exciting steam engines in a railroad museum near Vienna (Austria)” }
string(5) “2#080” string(3) “—” array(1) { [0]=> string(32) “IPTC Photo Metadata WorkingGroup” }
string(5) “2#055” string(3) “—” array(1) { [0]=> string(8) “20191123” }
string(5) “2#060” string(3) “—” array(1) { [0]=> string(6) “000000” }
string(5) “2#025” string(3) “—” array(2) { [0]=> string(8) “railroad” [1]=> string(12) “steam engine” }
string(5) “2#116” string(3) “—” array(1) { [0]=> string(38) “© Copyright 2019, IPTC – www.iptc.org” }
string(5) “2#110” string(3) “—” array(1) { [0]=> string(4) “IPTC” }

Fetching data:
1#090 — %G
1#000 —
2#000 —
2#120 — Front part views of three exciting steam engines in a railroad museum near Vienna (Austria)
2#080 — IPTC Photo Metadata WorkingGroup
2#055 — 20191123
2#060 — 000000
2#025 — railroad
2#025 — steam engine
2#116 — © Copyright 2019, IPTC – www.iptc.org
2#110 — IPTC

Example  2: The following code demonstrates the function when no data is present in the image. 

PHP




<?PHP
     
$img_size = getimagesize(
    $img_info);
  
echo var_dump($img_info);
$iptc_data = iptcparse($img_info['APP13']);
  
?>


Output:

array(2) { [“APP0”]=> string(14) “JFIF“” [“APP1”]=> string(32) “ExifMM*” }
Notice:
Undefined index: APP13 in C:\xampp\htdocs\GeeksForGeeks\contentReviewJuly\iptcparse\indexCopy.php on line 4

As we can see there is no IPTC block present in the image, it throws an error.

Reference:  https://www.php.net/manual/en/function.iptcparse.php

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS