예제 #1
0
 /**
  * @param SplFileInfo $file
  * @return bool
  */
 private function load(SplFileInfo $file)
 {
     try {
         $this->exifData = $this->exif->read($file->getRealPath());
         $this->date = $this->exifData->getCreationDate();
     } catch (\RuntimeException $e) {
         // do nothing
     }
 }
예제 #2
0
파일: ExifTest.php 프로젝트: Smony/njphoto
 /**
  * @group exif
  * @covers \PHPExif\Exif::getGPS
  */
 public function testGetGPS()
 {
     $expected = '40.333452380556,-20.167314813889';
     $data[\PHPExif\Exif::GPS] = $expected;
     $this->exif->setData($data);
     $this->assertEquals($expected, $this->exif->getGPS());
 }
예제 #3
0
 /**
  * Get an array with the dimensions of an image, together with its
  * aspectratio and some other info.
  *
  * @param string  $filename
  * @param boolean $safe
  *
  * @return array Specifics
  */
 public function imageInfo($filename, $safe)
 {
     // This function is vulnerable to path traversal, so blocking it in
     // safe mode for now.
     if ($safe) {
         return null;
     }
     $fullpath = sprintf('%s/%s', $this->app['resources']->getPath('filespath'), $filename);
     if (!is_readable($fullpath) || !is_file($fullpath)) {
         return false;
     }
     $types = array(0 => 'unknown', 1 => 'gif', 2 => 'jpeg', 3 => 'png', 4 => 'swf', 5 => 'psd', 6 => 'bmp');
     // Get the dimensions of the image
     $imagesize = getimagesize($fullpath);
     // Get the aspectratio
     if ($imagesize[1] > 0) {
         $ar = $imagesize[0] / $imagesize[1];
     } else {
         $ar = 0;
     }
     $info = array('width' => $imagesize[0], 'height' => $imagesize[1], 'type' => $types[$imagesize[2]], 'mime' => $imagesize['mime'], 'aspectratio' => $ar, 'filename' => $filename, 'fullpath' => realpath($fullpath), 'url' => str_replace('//', '/', $this->app['resources']->getUrl('files') . $filename));
     /** @var $reader \PHPExif\Reader\Reader */
     $reader = ExifReader::factory(ExifReader::TYPE_NATIVE);
     try {
         // Get the EXIF data of the image
         $exif = $reader->read($fullpath);
     } catch (\RuntimeException $e) {
         // No EXIF data… create an empty object.
         $exif = new Exif();
     }
     // GPS coordinates
     $gps = $exif->getGPS();
     $gps = explode(',', $gps);
     // If the picture is turned by exif, ouput the turned aspectratio
     if (in_array($exif->getOrientation(), array(6, 7, 8))) {
         $exifturned = $imagesize[1] / $imagesize[0];
     } else {
         $exifturned = $ar;
     }
     // Output the relevant EXIF info
     $info['exif'] = array('latitude' => isset($gps[0]) ? $gps[0] : false, 'longitude' => isset($gps[1]) ? $gps[1] : false, 'datetime' => $exif->getCreationDate(), 'orientation' => $exif->getOrientation(), 'aspectratio' => $exifturned ?: false);
     // Landscape if aspectratio > 5:4
     $info['landscape'] = $ar >= 1.25 ? true : false;
     // Portrait if aspectratio < 4:5
     $info['portrait'] = $ar <= 0.8 ? true : false;
     // Square-ish, if neither portrait or landscape
     $info['square'] = !$info['landscape'] && !$info['portrait'];
     return $info;
 }
예제 #4
0
 /**
  * Casts Exif to this sub-class.
  *
  * @param PHPExif\Exif $exif
  *
  * @return Exif
  */
 public static function cast(PHPExif\Exif $exif)
 {
     $new = new static($exif->getData());
     $new->setRawData($exif->getRawData());
     return $new;
 }