Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "cnlpete/image-metadata-parser",
"name": "tetronomis/image-metadata-parser",
"type": "library",
"description": "An abstraction to Exif, ITPC and XMP",
"keywords": ["php", "exif", "itpc"],
Expand Down
53 changes: 37 additions & 16 deletions imageMetadataParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ class ImageMetadataParser {
protected $sFilename;

protected $aAttributes = array();

protected $aRaw;

public function __construct($sFilename) {
$this->sFilename = $sFilename;
Expand All @@ -25,10 +27,13 @@ public static function exifAvailable() {
}

public function parseExif() {
$aArr = exif_read_data($this->sFilename, 'IFD0,THUMBNAIL', true);
$aArr = @exif_read_data($this->sFilename, 'IFD0,THUMBNAIL', true);
if ($aArr === false)
return false;


// Store raw data
$this->aRaw = $aArr;

// the date and time the image was taken
if (isset($aArr['IFD0']['DateTime'])) {
$iTimestamp = self::timestampFromEXIF($aArr['IFD0']['DateTime']);
Expand Down Expand Up @@ -66,11 +71,14 @@ public function parseExif() {
}

public function parseIPTC() {
$aArr = exif_read_data($this->sFilename, 'IDF0', true);
$aArr = @exif_read_data($this->sFilename, 'IDF0', true);
$size = getimagesize($this->sFilename, $info);
if(!isset($info['APP13']))
return false;

// Store raw data
$this->aRaw = $aArr;

$iptc = iptcparse($info['APP13']);

if (isset($iptc["2#120"][0])) # caption
Expand Down Expand Up @@ -160,6 +168,9 @@ public function hasGPS() {
isset($this->aAttributes['gps']['GPSLatitude'][0]);
}
public function getGPS(&$dLat, &$dLong) {
$dLong = $this->extractGPS($this->aAttributes['gps']['GPSLongitude'], $this->aAttributes['gps']['GPSLongitudeRef']);
$dLat = $this->extractGPS($this->aAttributes['gps']['GPSLatitude'], $this->aAttributes['gps']['GPSLatitudeRef']);
/*
$latFirst = explode("/", $this->aAttributes['gps']['GPSLatitude'][0]);
$latSecond = explode("/", $this->aAttributes['gps']['GPSLatitude'][1]);
$latThird = explode("/", $this->aAttributes['gps']['GPSLatitude'][2]);
Expand All @@ -179,6 +190,7 @@ public function getGPS(&$dLat, &$dLong) {
$longThird = intval($longThird[0]) / intval($longThird[1]);

$dLong = $longFirst + ($longSecond*60 + $longThird) / 3600;
*/
}
public function getGPSArray() {
$dLat = 0.0; $dLong = 0.0;
Expand All @@ -190,19 +202,28 @@ public function hasOrientation() {
return isset($this->aAttributes['orientation']);
}
public function getOrientation() {
switch($this->aAttributes['orientation']) {
case 3:
return 180;
break;
case 6:
return -90;
break;
case 8:
return 90;
break;
default:
return 0;
}
return $this->aAttributes['orientation'];
}
public function getRaw() {
return $this->aRaw;
}

private function extractGPS($exifCoord, $hemi) {
$degrees = count($exifCoord) > 0 ? $this->gps2Num($exifCoord[0]) : 0;
$minutes = count($exifCoord) > 1 ? $this->gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? $this->gps2Num($exifCoord[2]) : 0;
$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
return $flip * ($degrees + $minutes / 60 + $seconds / 3600);
}

private function gps2Num($coordPart) {
$parts = explode('/', $coordPart);
if (count($parts) <= 0)
return 0;

if (count($parts) == 1)
return $parts[0];

return floatval($parts[0]) / floatval($parts[1]);
}
}