-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexif.php
88 lines (78 loc) · 2.22 KB
/
exif.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php
class photo_time
{
public $fname;
public $tz;
public $date;
// derived values
public $timestamp; // UTC timestamp
function __construct($fname, $tz, $date)
{
$this->fname = $fname;
$this->tz = $tz;
$this->date = $date;
$this->make_timestamp();
}
function make_timestamp()
{
$str = "$this->date GMT";
$str .= ($this->tz > 0 ? "+" : "-");
$str .= $this->tz;
$this->timestamp = strtotime($str);
$offset_sec = $this->tz * 60 * 60;
$this->timestamp += ($this->tz > 0 ? -$offset_sec : $offset_sec);
}
function time_str()
{
return $this->date." ".($this->tz > 0 ? '+' : '-').$this->tz;
}
}
/// Returns an array of photo_time, given an array of file names.
function get_photo_times($fnames_array, $debug_cmd = FALSE)
{
$cmd = "bash -c 'exiftool -q -fast --TAG \"-EXIF:CreateDate\" --TAG \"-EXIF:TimeZoneOffset\" -d \"%Y-%m-%d %H:%M:%S\" -printFormat \"\\\$Directory/\\\$FileName, \\\$TimeZoneOffset, \\\$CreateDate\"";
foreach($fnames_array as $fname) $cmd .= " \"$fname\"";
$cmd .= "'";
if($debug_cmd) echo "$cmd\n";
$resp = `$cmd`;
if($resp == "")
{
echo "Unable to extract EXIF time information\n";
return FALSE;
}
$lines = explode("\n", $resp);
$info = array();
foreach($lines as $l)
{
$l = trim($l);
if($l == "") break;
$atoms = explode(",", $l);
$info[] = $foo = new photo_time(trim($atoms[0]), trim($atoms[1]), trim($atoms[2]));
}
return $info;
}
/// Generate and execute the call to exiftool to set the GPS parameters.
function set_photo_gps_info($fname, $lat, $lat_ref, $long, $long_ref, $timestamp)
{
$cmd = "bash -c 'exiftool -overwrite_original -P -q -fast ";
$cmd .= "\"-GPSDateStamp=".date("Y:m:d", $timestamp)."\" ";
$cmd .= "\"-GPSDateTime=".date("Y:m:d H:i:s", $timestamp)."\" ";
$cmd .= "\"-GPSLatitude=".$lat[0]." ".$lat[1]." ".$lat[2]."\" ";
$cmd .= "\"-GPSLatitudeRef=".$lat_ref."\" ";
$cmd .= "\"-GPSLongitude=".$long[0]." ".$long[1]." ".$long[2]."\" ";
$cmd .= "\"-GPSLongitudeRef=".$long_ref."\" ";
$cmd .= "\"-GPSTimeStamp=".date("H:i:s", $timestamp)."\"";
$cmd .= " \"$fname\"'";
if(TAGGER_DEBUG) echo "[debug] ".$cmd."\n";
if(!DRY_RUN) `$cmd`;
}
function usage($argv)
{
array_shift($argv);
if($pt = get_photo_times($argv))
{
var_dump($pt);
}
}
//usage($argv);
?>