Note Submitter: Vital
----
<?
// Touch file $image_file and set creation date based on date from EXIF
//
// @return Integer
// NULL - if no EXIF data
// 1 - creation date changed
// 2 - no change needed (same dates)
// 0 - colud not touch
function touch_exif($image_file)
{
$info=exif_read_data($image_file);
if (!$info) return NULL;
$datetime=isset($info['DateTime'])?
$info['DateTime']:
(isset($info['DateTimeOriginal'])?
$info['DateTimeOriginal']:
(isset($info['DateTimeDigitized'])?
$info['DateTimeDigitized']:
false));
$filetime=isset($info['FileDateTime'])?
$info['FileDateTime']:
false;
if(!$datetime) return NULL;
//0 yyyy:mm:dd, 1 hh:mm:ss
$datetime=explode(' ',$datetime);
list($y,$m,$d)=explode(':', $datetime[0]);
list($hh,$mm,$ss)=explode(':', $datetime[1]);
$datetime=mktime($hh, $mm, $ss, $m, $d, $y, 0);
if ($datetime==$filetime) return 2;
return (int)touch($argv[1], $datetime);
}
?>
Example of usage. Command line creation date changer.
<?
if($argc<2) die('Usage: php '.$argv[0].' image_name.jpg');
switch (touch_exif($argv[1]))
{
case NULL:die('EXIF date not found');
case 0:die('Fail. Do i have access?');
case 1:die('Success');
case 2:die('No change needed');
}
?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.