Example #1
0
 /**
  *
  */
 public static function createFromEnvironment()
 {
     $serverInfo = new self();
     if (stripos($_SERVER['SERVER_SOFTWARE'], 'apache') !== false) {
         $serverInfo->setSoftware(self::APACHE);
         $serverInfo->setSoftwareName('apache');
     }
     if (stripos($_SERVER['SERVER_SOFTWARE'], 'litespeed') !== false) {
         $serverInfo->setSoftware(self::LITESPEED);
         $serverInfo->setSoftwareName('litespeed');
     }
     if (strpos($_SERVER['SERVER_SOFTWARE'], 'nginx') !== false) {
         $serverInfo->setSoftware(self::NGINX);
         $serverInfo->setSoftwareName('nginx');
     }
     if (strpos($_SERVER['SERVER_SOFTWARE'], 'Microsoft-IIS') !== false || strpos($_SERVER['SERVER_SOFTWARE'], 'ExpressionDevServer') !== false) {
         $serverInfo->setSoftware(self::IIS);
         $serverInfo->setSoftwareName('iis');
     }
     $serverInfo->setHandler(php_sapi_name());
     return $serverInfo;
 }
Example #2
0
 /**
  * Read from a file
  *
  * @deprecated  Use img.io.MetaDataReader instead
  * @param   io.File file
  * @param   var default default void what should be returned in case no data is found
  * @return  img.util.ExifData
  * @throws  lang.FormatException in case malformed meta data is encountered
  * @throws  lang.ElementNotFoundException in case no meta data is available
  * @throws  img.ImagingException in case reading meta data fails
  */
 public static function fromFile(File $file)
 {
     if (FALSE === getimagesize($file->getURI(), $info)) {
         $e = new ImagingException('Cannot read image information from ' . $file->getURI());
         xp::gc(__FILE__);
         throw $e;
     }
     if (!isset($info['APP1'])) {
         if (func_num_args() > 1) {
             return func_get_arg(1);
         }
         throw new ElementNotFoundException('Cannot get EXIF information from ' . $file->getURI() . ' (no APP1 marker)');
     }
     if (!($info = exif_read_data($file->getURI(), 'COMPUTED,FILE,IFD0,EXIF,COMMENT,MAKERNOTE', TRUE, FALSE))) {
         throw new FormatException('Cannot get EXIF information from ' . $file->getURI());
     }
     // Change key case for lookups
     foreach ($info as &$val) {
         $val = array_change_key_case($val, CASE_LOWER);
     }
     with($e = new self());
     // COMPUTED info
     $e->setWidth(self::lookup($info['COMPUTED'], 'width'));
     $e->setHeight(self::lookup($info['COMPUTED'], 'height'));
     $e->setApertureFNumber(self::lookup($info['COMPUTED'], 'aperturefnumber'));
     // IFD0 info
     $e->setMake(trim(self::lookup($info['IFD0'], 'make')));
     $e->setModel(trim(self::lookup($info['IFD0'], 'model')));
     $e->setSoftware(self::lookup($info['IFD0'], 'software'));
     if (NULL !== ($o = self::lookup($info['IFD0'], 'orientation'))) {
         $e->setOrientation($o);
     } else {
         $e->setOrientation($e->width / $e->height > 1.0 ? 1 : 5);
     }
     // FILE info
     $e->setFileName(self::lookup($info['FILE'], 'filename'));
     $e->setFileSize(self::lookup($info['FILE'], 'filesize'));
     $e->setMimeType(self::lookup($info['FILE'], 'mimetype'));
     // EXIF info
     $e->setExposureTime(self::lookup($info['EXIF'], 'exposuretime'));
     $e->setExposureProgram(self::lookup($info['EXIF'], 'exposureprogram'));
     $e->setMeteringMode(self::lookup($info['EXIF'], 'meteringmode'));
     $e->setIsoSpeedRatings(self::lookup($info['EXIF'], 'isospeedratings'));
     // Sometimes white balance is in MAKERNOTE - e.g. FUJIFILM's Finepix
     if (NULL !== ($w = self::lookup($info['EXIF'], 'whitebalance'))) {
         $e->setWhiteBalance($w);
     } else {
         if (isset($info['MAKERNOTE']) && NULL !== ($w = self::lookup($info['MAKERNOTE'], 'whitebalance'))) {
             $e->setWhiteBalance($w);
         } else {
             $e->setWhiteBalance(NULL);
         }
     }
     // Extract focal length. Some models store "80" as "80/1", rip off
     // the divisor "1" in this case.
     if (NULL !== ($l = self::lookup($info['EXIF'], 'focallength'))) {
         sscanf($l, '%d/%d', $n, $frac);
         $e->setFocalLength(1 == $frac ? $n : $n . '/' . $frac);
     } else {
         $e->setFocalLength(NULL);
     }
     // Check for Flash and flashUsed keys
     if (NULL !== ($f = self::lookup($info['EXIF'], 'flash'))) {
         $e->setFlash($f);
     } else {
         $e->setFlash(NULL);
     }
     if (NULL !== ($date = self::lookup($info['EXIF'], 'datetimeoriginal', 'datetimedigitized'))) {
         $t = sscanf($date, '%4d:%2d:%2d %2d:%2d:%2d');
         $e->setDateTime(new Date(mktime($t[3], $t[4], $t[5], $t[1], $t[2], $t[0])));
     }
     return $e;
 }