note 102718 added to function.exif-read-data
| From: | Vital at osu1 dot php dot net | Date: | Wed, 02 Mar 2011 00:47:44 +0000 |
| Subject: | note 102718 added to function.exif-read-data | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-177477@lists.php.net to get a copy of this message | ||
<?
// 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');
}
?>
----
Server IP: 78.41.111.10
Probable Submitter: 95.220.169.54
----
Manual Page -- http://www.php.net/manual/en/function.exif-read-data.php
Edit -- https://master.php.net/note/edit/102718
Del: integrated -- https://master.php.net/note/delete/102718/integrated
Del: useless -- https://master.php.net/note/delete/102718/useless
Del: bad code -- https://master.php.net/note/delete/102718/bad+code
Del: spam -- https://master.php.net/note/delete/102718/spam
Del: non-english -- https://master.php.net/note/delete/102718/non-english
Del: in docs -- https://master.php.net/note/delete/102718/in+docs
Del: other reasons-- https://master.php.net/note/delete/102718
Reject -- https://master.php.net/note/reject/102718
Search -- https://master.php.net/manage/user-notes.php