本文整理汇总了PHP中read_exif_data函数的典型用法代码示例。如果您正苦于以下问题:PHP read_exif_data函数的具体用法?PHP read_exif_data怎么用?PHP read_exif_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_exif_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_exif_data
function get_exif_data($imagePath)
{
$exif_ifd0 = read_exif_data($imagePath, 'IFD0', 0);
$exif_exif = read_exif_data($imagePath, 'EXIF', 0);
$notFound = NULL;
$data = array();
if ($exif_ifd0 !== FALSE) {
// Make
if (array_key_exists('Make', $exif_ifd0)) {
$data['camMake'] = $exif_ifd0['Make'];
} else {
$data['camMake'] = $notFound;
}
// Model
if (array_key_exists('Model', $exif_ifd0)) {
$data['camModel'] = $exif_ifd0['Model'];
} else {
$data['camModel'] = $notFound;
}
// Exposure
if (array_key_exists('ExposureTime', $exif_ifd0)) {
$data['camExposure'] = $this->exif_get_fraction($exif_ifd0['ExposureTime']);
} else {
$data['camExposure'] = $notFound;
}
// Aperture - przesłona
if (array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
$data['camAperture'] = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} else {
$data['camAperture'] = $notFound;
}
// Date
if (array_key_exists('DateTime', $exif_ifd0)) {
$data['camDate'] = $exif_ifd0['DateTime'];
} else {
$data['camDate'] = $notFound;
}
// Software
if (array_key_exists('Software', $exif_ifd0)) {
$data['camSoftware'] = $exif_ifd0['Software'];
} else {
$data['camSoftware'] = $notFound;
}
// Focal - ogniskowa
if (array_key_exists('FocalLength', $exif_ifd0)) {
$data['camFocal'] = $this->exif_get_fraction($exif_ifd0['FocalLength']);
} else {
$data['camFocal'] = $notFound;
}
}
if ($exif_exif !== FALSE) {
// ISO
if (array_key_exists('ISOSpeedRatings', $exif_exif)) {
$data['camIso'] = $exif_exif['ISOSpeedRatings'];
} else {
$data['camIso'] = $notFound;
}
}
return $data;
}
示例2: getInformation
function getInformation($imagePath)
{
if (isset($imagePath) and file_exists($imagePath)) {
$ifdo = read_exif_data($imagePath, 'IFD0', 0);
$exif = read_exif_data($imagePath, 'EXIF', 0);
// Maker
if (@array_key_exists('Make', $ifdo)) {
$maker = $ifdo['Make'];
} else {
$maker = $this->unavailable;
}
// Model
if (@array_key_exists('Model', $ifdo)) {
$model = $ifdo['Model'];
} else {
$model = $this->unavailable;
}
// Exposure
if (@array_key_exists('ExposureTime', $ifdo)) {
$exposure = $ifdo['ExposureTime'];
} else {
$exposure = $this->unavailable;
}
// Aperture
if (@array_key_exists('ApertureFNumber', $ifdo['COMPUTED'])) {
$aperture = $ifdo['COMPUTED']['ApertureFNumber'];
} else {
$aperture = $this->unavailable;
}
// Created Date
if (@array_key_exists('DateTime', $ifdo)) {
$createDate = $ifdo['DateTime'];
} else {
$createDate = $this->unavailable;
}
// ISO
if (@array_key_exists('ISOSpeedRatings', $exif)) {
$iso = $exif['ISOSpeedRatings'];
} else {
$iso = $this->unavailable;
}
// Focal Length
if (@array_key_exists('FocalLength', $exif)) {
$focalLength = $exif['FocalLength'];
} else {
$focalLength = $this->unavailable;
}
$infoArray = array();
$infoArray['maker'] = $maker;
$infoArray['model'] = $model;
$infoArray['exposure'] = $exposure;
$infoArray['aperture'] = $aperture;
$infoArray['date'] = $createDate;
$infoArray['iso'] = $iso;
$infoArray['focalLength'] = $focalLength;
return $infoArray;
} else {
return false;
}
}
示例3: cameraUsed
public static function cameraUsed($imagePath)
{
// Check if the variable is set and if the file itself exists before continuing
if (isset($imagePath) and file_exists($imagePath)) {
// There are 2 arrays which contains the information we are after, so it's easier to state them both
$exif_ifd0 = read_exif_data($imagePath, 'IFD0', 0);
$exif_exif = read_exif_data($imagePath, 'EXIF', 0);
//error control
$notFound = "Unavailable";
// Make
if (@array_key_exists('Make', $exif_ifd0)) {
$camMake = $exif_ifd0['Make'];
} else {
$camMake = $notFound;
}
// Model
if (@array_key_exists('Model', $exif_ifd0)) {
$camModel = $exif_ifd0['Model'];
} else {
$camModel = $notFound;
}
// Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0)) {
$camExposure = $exif_ifd0['ExposureTime'];
} else {
$camExposure = $notFound;
}
// Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED'])) {
$camAperture = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} else {
$camAperture = $notFound;
}
// Date
if (@array_key_exists('DateTime', $exif_ifd0)) {
$camDate = $exif_ifd0['DateTime'];
} else {
$camDate = $notFound;
}
// ISO
if (@array_key_exists('ISOSpeedRatings', $exif_exif)) {
$camIso = $exif_exif['ISOSpeedRatings'];
} else {
$camIso = $notFound;
}
$return = array();
$return['make'] = $camMake;
$return['model'] = $camModel;
$return['exposure'] = $camExposure;
$return['aperture'] = $camAperture;
$return['date'] = $camDate;
$return['iso'] = $camIso;
return $return;
} else {
return false;
}
}
示例4: __construct
public function __construct($fileName)
{
// *** Open up the file
$this->image = $this->openImage($fileName);
logr($this->image, 'openIMage');
// *** Get width and height
$this->width = imagesx($this->image);
$this->height = imagesy($this->image);
// *** Get EXIF data if the exif module is installed
if (function_exists('read_exif_data')) {
$this->exif = read_exif_data($fileName);
} else {
error_log("Please install the exif module in order to support image orientation");
}
}
示例5: removeExif
/**
* Remove EXIF data if needed
*
* @param $file
* @return bool
* @throws Exception
*/
private static function removeExif($file)
{
if ($exif = @read_exif_data($file)) {
if (!empty($exif['Orientation'])) {
$img = new SimpleImage($file);
if ($img->save()) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}
示例6: update_exif
/**
* @param Image $image
*/
protected function update_exif(Image $image)
{
$tmpFilename = tempnam(sys_get_temp_dir(), 'upload_image_');
// Fixes error reading gaufrette streaf for read_exif_data
file_put_contents($tmpFilename, file_get_contents($this->getFilepath($image)));
$exif = new ExifDataParser(@read_exif_data($tmpFilename) ?: array());
unlink($tmpFilename);
$exif_parsed = $exif->getParsed();
$image->setExifData($exif_parsed);
$datetime = null;
try {
$datetime = new \DateTime(@$exif_parsed['DateTimeOriginal']);
} catch (\Exception $e) {
$datetime = new \DateTime($exif_parsed['DateTime']);
}
$image->setTakenAt($datetime);
$this->em->persist($image);
}
示例7: initFromPath
/**
* Initialize a layer from a given image path
*
* From an upload form, you can give the "tmp_name" path
*
* @param string $path
* @param bool $fixOrientation
*
* @return ImageWorkshopLayer
*/
public static function initFromPath($path, $fixOrientation = false)
{
if (!file_exists($path)) {
throw new ImageWorkshopException(sprintf('File "%s" not exists.', $path), static::ERROR_IMAGE_NOT_FOUND);
}
if (false === ($imageSizeInfos = @getImageSize($path))) {
throw new ImageWorkshopException('Can\'t open the file at "' . $path . '" : file is not readable, did you check permissions (755 / 777) ?', static::ERROR_NOT_READABLE_FILE);
}
$mimeContentType = explode('/', $imageSizeInfos['mime']);
if (!$mimeContentType || !isset($mimeContentType[1])) {
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
}
$mimeContentType = $mimeContentType[1];
$exif = array();
switch ($mimeContentType) {
case 'jpeg':
$image = imageCreateFromJPEG($path);
if (false === ($exif = @read_exif_data($path))) {
$exif = array();
}
break;
case 'gif':
$image = imageCreateFromGIF($path);
break;
case 'png':
$image = imageCreateFromPNG($path);
break;
default:
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "' . $path . '"', static::ERROR_NOT_AN_IMAGE_FILE);
break;
}
if (false === $image) {
throw new ImageWorkshopException('Unable to create image with file found at "' . $path . '"');
}
$layer = new ImageWorkshopLayer($image, $exif);
if ($fixOrientation) {
$layer->fixOrientation();
}
return $layer;
}
示例8: __construct
/**
* Constructor function
* Sets the values for a list of variabhles
* Also grabs the image dimensions and orientation during the process
*
* @param object $image
*/
public function __construct($image)
{
$this->temp_name = $image;
$image = getimagesize($this->temp_name);
$this->orig_x = $image[0];
$this->orig_y = $image[1];
$this->file_type = strtolower(preg_replace('/^.*?\\//', '', $image['mime']));
$this->thumb_size = 200;
$this->med_size = 300;
$this->large_size = 450;
$this->quality = 100;
//default
if ($this->file_type == 'jpg' || $this->file_type == 'jpeg') {
$exif = @read_exif_data($this->temp_name);
if (isset($exif['Orientation'])) {
$this->orientation = $exif['Orientation'];
} else {
$this->orientation = 1;
}
} else {
$this->orientation = 1;
}
}
示例9: populateMetadata
/**
* Populates the metadata of a photo based on the EXIF data of the photo
*
* @param \Photo\Model\Photo $photo the photo to add the metadata to.
* @param string $path The path where the actual image file is stored
*
* @return \Photo\Model\Photo the photo with the added metadata
*/
public function populateMetadata($photo, $path)
{
$exif = read_exif_data($path, 'EXIF');
if ($exif) {
$photo->setArtist($exif['Artist']);
$photo->setCamera($exif['Model']);
$photo->setDateTime(new \DateTime($exif['DateTimeOriginal']));
$photo->setFlash($exif['Flash'] != 0);
$photo->setFocalLength($this->frac2dec($exif['FocalLength']));
$photo->setExposureTime($this->frac2dec($exif['ExposureTime']));
if (isset($exif['ShutterSpeedValue'])) {
$photo->setShutterSpeed($this->exifGetShutter($exif['ShutterSpeedValue']));
}
if (isset($exif['ShutterSpeedValue'])) {
$photo->setAperture($this->exifGetFstop($exif['ApertureValue']));
}
$photo->setIso($exif['ISOSpeedRatings']);
} else {
// We must have a date/time for a photo
// Since no date is known, we use the current one
$photo->setDateTime(new \DateTime());
}
return $photo;
}
示例10: process
function process()
{
$site_id = $this->site_id;
$counts = array();
for ($i = 1; $i <= $this->max_upload_number; $i++) {
$element = $this->get_element('upload_' . $i);
if (!empty($element->tmp_full_path) and file_exists($element->tmp_full_path)) {
$filename = $this->get_value('upload_' . $i . '_filename');
if ($this->verify_image($element->tmp_full_path)) {
if (empty($counts[$filename])) {
$this->files[$filename] = $element->tmp_full_path;
$counts[$filename] = 1;
} else {
$counts[$filename]++;
$this->files[$filename . '.' . $counts[$filename]] = $element->tmp_full_path;
}
} else {
$this->invalid_files[$filename] = $element->tmp_full_path;
}
}
}
if (count($this->files)) {
$page_id = (int) $this->get_value('attach_to_page');
$max_sort_order_value = 0;
if ($page_id) {
$max_sort_order_value = $this->_get_max_sort_order_value($page_id);
}
$sort_order_value = $max_sort_order_value;
$tables = get_entity_tables_by_type(id_of('image'));
$valid_file_html = '<ul>' . "\n";
foreach ($this->files as $entry => $cur_name) {
$sort_order_value++;
$valid_file_html .= '<li><strong>' . $entry . ':</strong> processing ';
$date = '';
// get suffix
$type = strtolower(substr($cur_name, strrpos($cur_name, '.') + 1));
$ok_types = array('jpg');
// get exif data
if ($this->get_value('exif_override') && in_array($type, $ok_types) && function_exists('read_exif_data')) {
// read_exif_data() does not obey error supression
$exif_data = @read_exif_data($cur_name);
if ($exif_data) {
// some photos may have different fields filled in for dates - look through these until one is found
$valid_dt_fields = array('DateTimeOriginal', 'DateTime', 'DateTimeDigitized');
foreach ($valid_dt_fields as $field) {
// once we've found a valid date field, store that and break out of the loop
if (!empty($exif_data[$field])) {
$date = $exif_data[$field];
break;
}
}
}
} else {
$date = $this->get_value('datetime');
}
$keywords = $entry;
if ($this->get_value('keywords')) {
$keywords .= ', ' . $this->get_value('keywords');
}
// insert entry into DB with proper info
$values = array('datetime' => $date, 'image_type' => $type, 'author' => $this->get_value('author'), 'state' => 'Pending', 'keywords' => $keywords, 'description' => $this->get_value('description'), 'name' => $this->get_value('name') ? $this->get_value('name') : $entry, 'content' => $this->get_value('content'), 'original_image_format' => $this->get_value('original_image_format'), 'new' => 0, 'no_share' => $this->get_value('no_share'));
//tidy values
$no_tidy = array('state', 'new');
foreach ($values as $key => $val) {
if (!in_array($key, $no_tidy) && !empty($val)) {
$values[$key] = trim(get_safer_html(tidy($val)));
}
}
$id = reason_create_entity($site_id, id_of('image'), $this->user_id, $entry, $values);
if ($id) {
//assign to categories
$categories = $this->get_value('assign_to_categories');
if (!empty($categories)) {
foreach ($categories as $category_id) {
create_relationship($id, $category_id, relationship_id_of('image_to_category'));
}
}
//assign to gallery page
if ($page_id) {
create_relationship($page_id, $id, relationship_id_of('minisite_page_to_image'), array('rel_sort_order' => $sort_order_value));
}
// resize and move photos
$new_name = PHOTOSTOCK . $id . '.' . $type;
$orig_name = PHOTOSTOCK . $id . '_orig.' . $type;
$tn_name = PHOTOSTOCK . $id . '_tn.' . $type;
// Support for new fields; they should be set null by default, but will be
// changed below if a thumbnail/original image is created. This is very messy...
$thumbnail_image_type = null;
$original_image_type = null;
// atomic move the file if possible, copy if necessary
if (is_writable($cur_name)) {
rename($cur_name, $new_name);
} else {
copy($cur_name, $new_name);
}
// create a thumbnail if need be
list($width, $height, $type, $attr) = getimagesize($new_name);
if ($width > REASON_STANDARD_MAX_IMAGE_WIDTH || $height > REASON_STANDARD_MAX_IMAGE_HEIGHT) {
copy($new_name, $orig_name);
resize_image($new_name, REASON_STANDARD_MAX_IMAGE_WIDTH, REASON_STANDARD_MAX_IMAGE_HEIGHT);
//.........这里部分代码省略.........
示例11: getLongLat
/**
* Gets Longitude and Latitude information from a photo exif data, if exists.
*
* @return mixed array of longitude and latitude or false otherwise
*/
public function getLongLat()
{
try {
$exif = read_exif_data('upload/photos/' . $this->id . '.' . $this->extension);
if (isset($exif["GPSLongitude"], $exif['GPSLongitudeRef'], $exif["GPSLatitude"], $exif['GPSLatitudeRef'])) {
$lon = $this->getGps($exif["GPSLongitude"], $exif['GPSLongitudeRef']);
$lat = $this->getGps($exif["GPSLatitude"], $exif['GPSLatitudeRef']);
return array('lat' => $lat, 'long' => $lon);
}
} catch (Exception $e) {
}
return false;
}
示例12: parse
/**
* Pareses and stores all relevant exif data
*/
protected function parse()
{
// read the exif data of the media object if possible
$this->data = @read_exif_data($this->media->root());
// stop on invalid exif data
if (!is_array($this->data)) {
return false;
}
// store the timestamp when the picture has been taken
if (isset($this->data['DateTime'])) {
$this->timestamp = strtotime($this->data['DateTime']);
} else {
$this->timestamp = a::get($this->data, 'FileDateTime', $this->media->modified());
}
// exposure
$this->exposure = a::get($this->data, 'ExposureTime');
// iso
$this->iso = a::get($this->data, 'ISOSpeedRatings');
// focal length
if (isset($this->data['FocalLength'])) {
$this->focalLength = $this->data['FocalLength'];
} else {
if (isset($this->data['FocalLengthIn35mmFilm'])) {
$this->focalLength = $this->data['FocalLengthIn35mmFilm'];
}
}
// aperture
$this->aperture = @$this->data['COMPUTED']['ApertureFNumber'];
// color or bw
$this->isColor = @$this->data['COMPUTED']['IsColor'] == true;
}
示例13: saveFileToDB
public function saveFileToDB($filepath, $userid)
{
ini_set('exif.encode_unicode', 'UTF-8');
error_log($filepath);
try {
try {
$exif_ifd0 = read_exif_data($filepath, 'IFD0', 0);
$exif_exif = read_exif_data($filepath, 'EXIF', 0);
$exif_file = read_exif_data($filepath, 'FILE', 0);
} catch (Exception $e) {
}
$timetaken = null;
$filename = $exif_file['FileName'];
if (isset($exif_exif['DateTimeOriginal'])) {
//We get the date and time the picture was taken
try {
$exif_date = $exif_exif['DateTimeOriginal'];
error_log("EXIF TIME TAKEN : " . $exif_date);
$exif_timetaken = date("Y-m-d H:i:s", strtotime($exif_date));
} catch (Exception $e) {
error_log($e->getMessage());
}
}
if (isset($exif_ifd0['DateTime'])) {
//We get the date and time the picture was taken
try {
$ifd0_date = $exif_ifd0['DateTime'];
error_log("IFDO TIME TAKEN : " . $ifd0_date);
$ifd0_timetaken = date("Y-m-d H:i:s", strtotime($ifd0_date));
} catch (Exception $e) {
error_log($e->getMessage());
}
}
//We chose the earliest date of the 2
if (isset($exif_date) && isset($ifd0_date)) {
$rawTimeTaken = $exif_date < $ifd0_date ? $exif_date : $ifd0_date;
error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
$timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
} else {
if (isset($exif_date)) {
$rawTimeTaken = $exif_date;
error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
$timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
} else {
if (isset($ifd0_date)) {
$rawTimeTaken = $ifd0_date;
error_log("FINAL TIME TAKEN : " . $rawTimeTaken);
$timetaken = date("Y-m-d H:i:s", strtotime($rawTimeTaken));
} else {
$rawTimeTaken = $exif_file['FileDateTime'];
$timetaken = date("Y-m-d H:i:s", $rawTimeTaken);
}
}
}
error_log("TIME TAKEN : " . $timetaken);
$fileType = $exif_file['MimeType'];
//$payload = file_get_contents($filepath);
$picture = new Picture(0, "", "", $timetaken, $fileType, null, $filename);
$picture->latitude = "";
$picture->longitude = "";
$dao = new PictureDAO();
$dayId = $dao->createDay($userid, $timetaken);
$dao->savePicture($dayId, $picture);
error_log("File saved successfully.");
//unlink($filepath);
} catch (Exception $e3) {
print "Error!: " . $e3->getMessage() . "<br/>";
//unlink($filepath);
}
}
示例14: read_exif_data
<?php
/* Prototype : array read_exif_data ( string $filename [, string $sections [, bool $arrays [, bool $thumbnail ]]] )
* Description: Alias of exif_read_data()
* Source code: ext/exif/exif.c
*/
echo "*** Testing read_exif_data() : basic functionality ***\n";
print_r(read_exif_data(dirname(__FILE__) . '/test2.jpg'));
?>
===Done===
示例15: get_exif_data
/**
* returns informations from EXIF metadata, mapping is done in this function.
*
* @param string $filename
* @param array $map
* @return array
*/
function get_exif_data($filename, $map)
{
global $conf;
$result = array();
if (!function_exists('read_exif_data')) {
die('Exif extension not available, admin should disable exif use');
}
// Read EXIF data
if ($exif = @read_exif_data($filename) or $exif2 = trigger_change('format_exif_data', $exif = null, $filename, $map)) {
if (!empty($exif2)) {
$exif = $exif2;
} else {
$exif = trigger_change('format_exif_data', $exif, $filename, $map);
}
// configured fields
foreach ($map as $key => $field) {
if (strpos($field, ';') === false) {
if (isset($exif[$field])) {
$result[$key] = $exif[$field];
}
} else {
$tokens = explode(';', $field);
if (isset($exif[$tokens[0]][$tokens[1]])) {
$result[$key] = $exif[$tokens[0]][$tokens[1]];
}
}
}
// GPS data
$gps_exif = array_intersect_key($exif, array_flip(array('GPSLatitudeRef', 'GPSLatitude', 'GPSLongitudeRef', 'GPSLongitude')));
if (count($gps_exif) == 4) {
if (is_array($gps_exif['GPSLatitude']) and in_array($gps_exif['GPSLatitudeRef'], array('S', 'N')) and is_array($gps_exif['GPSLongitude']) and in_array($gps_exif['GPSLongitudeRef'], array('W', 'E'))) {
$result['latitude'] = parse_exif_gps_data($gps_exif['GPSLatitude'], $gps_exif['GPSLatitudeRef']);
$result['longitude'] = parse_exif_gps_data($gps_exif['GPSLongitude'], $gps_exif['GPSLongitudeRef']);
}
}
}
if (!$conf['allow_html_in_metadata']) {
foreach ($result as $key => $value) {
// in case the origin of the photo is unsecure (user upload), we remove
// HTML tags to avoid XSS (malicious execution of javascript)
$result[$key] = strip_tags($value);
}
}
return $result;
}