note 102718 deleted from function.exif-read-data by danbrown

From: Date: Wed, 02 Mar 2011 01:54:57 +0000
Subject: note 102718 deleted from function.exif-read-data by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-177480@lists.php.net to get a copy of this message
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'); } ?>

« previous php.notes (#177480) next »