本文整理汇总了PHP中read_exif_data_raw函数的典型用法代码示例。如果您正苦于以下问题:PHP read_exif_data_raw函数的具体用法?PHP read_exif_data_raw怎么用?PHP read_exif_data_raw使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了read_exif_data_raw函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: rotate_item
static function rotate_item($item)
{
// Only try to rotate photos based on EXIF
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
require_once MODPATH . "exif/lib/exif.php";
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
$orientation = $exif_raw["IFD0"]["Orientation"];
$degrees = 0;
if ($orientation == '3: Upside-down') {
$degrees = 180;
} else {
if ($orientation == '8: 90 deg CW') {
$degrees = -90;
} else {
if ($orientation == '6: 90 deg CCW') {
$degrees = 90;
}
}
}
if ($degrees) {
$tmpfile = tempnam(TMPPATH, "rotate");
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees));
$item->set_data_file($tmpfile);
$item->save();
unlink($tmpfile);
}
}
}
return;
}
示例2: beforeValidate
/**
* This callback method extract exif data from image and sets fields as customized in settings.
*
* @param Model $model Object of model
*
* @return boolean Return method's status
*/
function beforeValidate(&$model)
{
// If photo is uploaded
if (isset($model->data[$model->name][$this->settings[$model->name]['filename']]) && 0 == $model->data[$model->name][$this->settings[$model->name]['filename']]['error']) {
// Name of image file
//$filename = $model->data[$model->name][$this->settings[$model->name]['filename']]['tmp_name'];
$filename = WWW_ROOT . 'files' . DS . 'pictures' . DS . $model->data[$model->name][$this->settings[$model->name]['filename']];
// Read exif data from file
$exif = read_exif_data_raw($filename, 0);
// If exif data contains maker note then set it empty
if (isset($exif['SubIFD']['MakerNote'])) {
$exif['SubIFD']['MakerNote'] = '';
}
// Create new sanitize object and clean exif data
Sanitize::clean($exif);
if (isset($exif['SubIFD']['DateTimeOriginal']) && isset($this->settings[$model->name]['exifDateField'])) {
$model->data[$model->name][$this->settings[$model->name]['exifDateField']] = date($this->settings[$model->name]['exifDateFormat'], strtotime($exif['SubIFD']['DateTimeOriginal']));
}
// If the GPS Latitude and Longitude is set then add to proper fields
if (isset($exif['GPS'])) {
if (isset($this->settings[$model->name]['gpsLattitudeField'])) {
$model->data[$model->name][$this->settings[$model->name]['gpsLattitudeField']] = $exif['GPS']['Latitude'];
}
if (isset($this->settings[$model->name]['gpsLattitudeField'])) {
$model->data[$model->name][$this->settings[$model->name]['gpsLongitudeField']] = $exif['GPS']['Longitude'];
}
}
// Store serialized exif data in model's data
if (isset($this->settings[$model->name]['exifField'])) {
$model->data[$model->name][$this->settings[$model->name]['exifField']] = serialize($exif);
}
}
return true;
}
示例3: read
public function read()
{
$exif = array();
$exif_raw = read_exif_data_raw($this->filename, false);
$this->exif_raw = $exif_raw;
if (isset($exif_raw['ValidEXIFData'])) {
foreach ($this->exif_vars as $field => $exif_var) {
switch (count($exif_var)) {
case 1:
if (array_key_exists($exif_var[0], $exif_raw)) {
$exif[$field] = $exif_raw[$exif_var[0]];
}
break;
case 2:
if (array_key_exists($exif_var[0], $exif_raw) && array_key_exists($exif_var[1], $exif_raw[$exif_var[0]])) {
$exif[$field] = $exif_raw[$exif_var[0]][$exif_var[1]];
}
break;
case 3:
if (array_key_exists($exif_var[0], $exif_raw) && array_key_exists($exif_var[1], $exif_raw[$exif_var[0]]) && array_key_exists($exif_var[2], $exif_raw[$exif_var[0]][$exif_var[1]])) {
$exif[$field] = $exif_raw[$exif_var[0]][$exif_var[1]][$exif_var[2]];
}
break;
}
}
}
$this->exif = $exif;
return $exif;
}
示例4: serialize_exif
function serialize_exif($uploaded_file)
{
//$exif_tmp = read_exif_data_raw($_FILES['upload_file']['tmp_name'],0);
$exif_tmp = read_exif_data_raw($uploaded_file, 0);
$flat_exif_tmp = flatten_array($exif_tmp);
if (in_array("DataDumpMakerNote", $flat_exif_tmp)) {
// this field is set to empty because it causes trouble
$flat_exif_tmp['DataDumpMakerNote'] = NULL;
}
//search for all "unknown:*" fields because like the MakerNote it causes trouble.
// Thanks to erdbeerbaum for pointing this out.
foreach ($flat_exif_tmp as $key => $value) {
$pos = strpos($key, "unknown:");
if ($pos === 0) {
$flat_exif_tmp[$key] = NULL;
}
}
foreach ($flat_exif_tmp as $key => $value) {
$flat_exif_tmp[$key] = trim($value);
}
$exif_info = serialize($flat_exif_tmp);
// we need to escape the string before saving it to the db
$exif_info = mysql_real_escape_string($exif_info);
return $exif_info;
}
示例5: exif_parse_file
function exif_parse_file($filename)
{
global $CONFIG, $lang_picinfo;
//String containing all the available exif tags.
$exif_info = "AFFocusPosition|Adapter|ColorMode|ColorSpace|ComponentsConfiguration|CompressedBitsPerPixel|Contrast|CustomerRender|DateTimeOriginal|DateTimedigitized|DigitalZoom|DigitalZoomRatio|ExifImageHeight|ExifImageWidth|ExifInteroperabilityOffset|ExifOffset|ExifVersion|ExposureBiasValue|ExposureMode|ExposureProgram|ExposureTime|FNumber|FileSource|Flash|FlashPixVersion|FlashSetting|FocalLength|FocusMode|GainControl|IFD1Offset|ISOSelection|ISOSetting|ISOSpeedRatings|ImageAdjustment|ImageDescription|ImageSharpening|LightSource|Make|ManualFocusDistance|MaxApertureValue|MeteringMode|Model|NoiseReduction|Orientation|Quality|ResolutionUnit|Saturation|SceneCaptureMode|SceneType|Sharpness|Software|WhiteBalance|YCbCrPositioning|xResolution|yResolution";
if (!is_readable($filename)) {
return false;
}
$size = @getimagesize($filename);
if ($size[2] != 2) {
return false;
}
// Not a JPEG file
$exifRawData = explode("|", $exif_info);
$exifCurrentData = explode("|", $CONFIG['show_which_exif']);
//Let's build the string of current exif values to be shown
$showExifStr = "";
foreach ($exifRawData as $key => $val) {
if ($exifCurrentData[$key] == 1) {
$showExifStr .= "|" . $val;
}
}
//Check if we have the data of the said file in the table
$sql = "SELECT * FROM {$CONFIG['TABLE_EXIF']} " . "WHERE filename='" . addslashes($filename) . "'";
$result = cpg_db_query($sql);
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_array($result);
mysql_free_result($result);
$exifRawData = unserialize($row["exifData"]);
} else {
// No data in the table - read it from the image file
$exifRawData = read_exif_data_raw($filename, 0);
// Insert it into table for future reference
$sql = "INSERT INTO {$CONFIG['TABLE_EXIF']} " . "VALUES ('" . addslashes($filename) . "', '" . addslashes(serialize($exifRawData)) . "')";
$result = cpg_db_query($sql);
}
$exif = array();
if (is_array($exifRawData['IFD0'])) {
$exif = array_merge($exif, $exifRawData['IFD0']);
}
if (is_array($exifRawData['SubIFD'])) {
$exif = array_merge($exif, $exifRawData['SubIFD']);
}
if (is_array($exifRawData['SubIFD']['MakerNote'])) {
$exif = array_merge($exif, $exifRawData['SubIFD']['MakerNote']);
}
$exif['IFD1OffSet'] = $exifRawData['IFD1OffSet'];
$exifParsed = array();
foreach ($exif as $key => $val) {
if (strpos($showExifStr, "|" . $key) && isset($val)) {
$exifParsed[$lang_picinfo[$key]] = $val;
//$exifParsed[$key] = $val;
}
}
ksort($exifParsed);
return $exifParsed;
}
示例6: extract
static function extract($item)
{
$keys = array();
// Only try to extract EXIF from photos
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
$data = array();
require_once MODPATH . "exif/lib/exif.php";
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
foreach (self::_keys() as $field => $exifvar) {
if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) {
$value = $exif_raw[$exifvar[0]][$exifvar[1]];
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
$keys[$field] = Input::clean($value);
if ($field == "DateTime") {
$time = strtotime($value);
if ($time > 0) {
$item->captured = $time;
}
} else {
if ($field == "Caption" && !$item->description) {
$item->description = $value;
}
}
}
}
}
$size = getimagesize($item->file_path(), $info);
if (is_array($info) && !empty($info["APP13"])) {
$iptc = iptcparse($info["APP13"]);
foreach (array("Keywords" => "2#025", "Caption" => "2#120") as $keyword => $iptc_key) {
if (!empty($iptc[$iptc_key])) {
$value = implode(" ", $iptc[$iptc_key]);
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
$keys[$keyword] = Input::clean($value);
if ($keyword == "Caption" && !$item->description) {
$item->description = $value;
}
}
}
}
}
$item->save();
$record = ORM::factory("exif_record")->where("item_id", "=", $item->id)->find();
if (!$record->loaded()) {
$record->item_id = $item->id;
}
$record->data = serialize($keys);
$record->key_count = count($keys);
$record->dirty = 0;
$record->save();
}
示例7: read_exif_data_protected
/**
* Provides an [not] error protected read of image EXIF/IPTC data for PHP 4
*
* @param string $path image path
* @return array
*/
function read_exif_data_protected($path)
{
if (DEBUG_EXIF) {
debugLog("Begin read_exif_data_protected({$path})");
}
$rslt = read_exif_data_raw($path, false);
if (DEBUG_EXIF) {
debugLog("End read_exif_data_protected({$path})");
}
return $rslt;
}
示例8: rotate_item
static function rotate_item($item)
{
require_once MODPATH . 'autorotate/lib/pel/PelDataWindow.php';
require_once MODPATH . 'autorotate/lib/pel/PelJpeg.php';
require_once MODPATH . 'autorotate/lib/pel/PelTiff.php';
// Only try to rotate photos based on EXIF
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
require_once MODPATH . "exif/lib/exif.php";
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
$orientation = $exif_raw["IFD0"]["Orientation"];
$degrees = 0;
if ($orientation == '3: Upside-down') {
$degrees = 180;
} else {
if ($orientation == '8: 90 deg CW') {
$degrees = -90;
} else {
if ($orientation == '6: 90 deg CCW') {
$degrees = 90;
}
}
}
if ($degrees) {
$tmpfile = tempnam(TMPPATH, "rotate");
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees));
// Update EXIF info
$data = new PelDataWindow(file_get_contents($tmpfile));
if (PelJpeg::isValid($data)) {
$jpeg = $file = new PelJpeg();
$jpeg->load($data);
$exif = $jpeg->getExif();
if ($exif !== null) {
$tiff = $exif->getTiff();
$ifd0 = $tiff->getIfd();
$orientation = $ifd0->getEntry(PelTag::ORIENTATION);
$orientation->setValue(1);
file_put_contents($tmpfile, $file->getBytes());
}
}
$item->set_data_file($tmpfile);
$item->save();
unlink($tmpfile);
}
}
}
return;
}
示例9: exif_parse_file
function exif_parse_file($filename, $pid)
{
global $CONFIG, $lang_picinfo;
if (!is_readable($filename)) {
return false;
}
$size = cpg_getimagesize($filename);
if ($size[2] != 2) {
return false;
// Not a JPEG file
}
//String containing all the available exif tags.
$exif_info = "AFFocusPosition|Adapter|ColorMode|ColorSpace|ComponentsConfiguration|CompressedBitsPerPixel|Contrast|CustomerRender|DateTimeOriginal|DateTimedigitized|DigitalZoom|DigitalZoomRatio|ExifImageHeight|ExifImageWidth|ExifInteroperabilityOffset|ExifOffset|ExifVersion|ExposureBiasValue|ExposureMode|ExposureProgram|ExposureTime|FNumber|FileSource|Flash|FlashPixVersion|FlashSetting|FocalLength|FocusMode|GainControl|IFD1Offset|ISOSelection|ISOSetting|ISOSpeedRatings|ImageAdjustment|ImageDescription|ImageSharpening|LightSource|Make|ManualFocusDistance|MaxApertureValue|MeteringMode|Model|NoiseReduction|Orientation|Quality|ResolutionUnit|Saturation|SceneCaptureMode|SceneType|Sharpness|Software|WhiteBalance|YCbCrPositioning|xResolution|yResolution";
$exif_names = explode("|", $exif_info);
//Check if we have the data of the said file in the table
$result = cpg_db_query("SELECT exifData FROM {$CONFIG['TABLE_EXIF']} WHERE pid = {$pid}");
if (mysql_num_rows($result) > 0) {
$row = mysql_fetch_assoc($result);
mysql_free_result($result);
$exif = unserialize($row['exifData']);
// Convert old EXIF data style to new one
if (array_key_exists('Errors', $exif)) {
$exif = cpg_exif_strip_data($exif, $exif_names);
cpg_db_query("UPDATE {$CONFIG['TABLE_EXIF']} SET exifData = '" . addslashes(serialize($exif)) . "' WHERE pid = '{$pid}'");
}
} else {
// No data in the table - read it from the image file
$exifRawData = read_exif_data_raw($filename, 0);
$exif = cpg_exif_strip_data($exifRawData, $exif_names);
// Insert it into table for future reference
cpg_db_query("INSERT INTO {$CONFIG['TABLE_EXIF']} (pid, exifData) VALUES ({$pid}, '" . addslashes(serialize($exif)) . "')");
}
$exifParsed = array();
$exifCurrentData = array_keys(array_filter(explode("|", $CONFIG['show_which_exif'])));
foreach ($exifCurrentData as $i) {
$name = $exif_names[$i];
if (isset($exif[$name])) {
$exifParsed[$lang_picinfo[$name]] = $exif[$name];
}
}
ksort($exifParsed);
return $exifParsed;
}
示例10: actionDefault
function actionDefault()
{
// Get the ID from the URL
$id = $_GET['id'];
// Redirect if empty
if (empty($id)) {
die('No image selected.');
}
// Get the post ID
$item_id = substr($id, 5, strpos($id, '/') - 5);
// Get the weblog item
$item = @$this->weblog->getItemById($item_id);
if (!$item) {
die('Invalid image specified');
}
// Get the image object
$image = null;
foreach ($item['images'] as $key => $i) {
if ($i->relative_path == $id) {
$image = $i;
$image->previous = $key <= 0 ? null : $item['images'][$key - 1];
$image->next = $key >= sizeof($item['images']) - 1 ? null : $item['images'][$key + 1];
$image->num = $key + 1;
$image->total_images = sizeof($item['images']);
}
}
// Get the EXIF info for the image
$result = read_exif_data_raw($image->getAbsolutePath(), false);
$image->exif = array();
if (isset($result['IFD0'])) {
$image->exif = array_merge($image->exif, $result['IFD0']);
}
if (isset($result['SubIFD'])) {
$image->exif = array_merge($image->exif, $result['SubIFD']);
}
// Add them to the template
$this->tpl->assign('item', $item);
$this->tpl->assign('image', $image);
// Display the template
$this->display();
}
示例11: thumb_caption_mgr
function thumb_caption_mgr($rowset)
{
global $CONFIG;
foreach ($rowset as $ind => $val) {
$pic_data = $rowset[$ind];
$pic_data['title'] = 'Filename - title: ' . $pic_data['filename'] . ', no: ' . $i;
$fullpath = $CONFIG['fullpath'] . $val['filepath'] . $val['filename'];
$exif = read_exif_data_raw($fullpath, true);
$str = '';
foreach ($exif as $key => $val) {
if ($key == 'SubIFD') {
$str = substr($val['UserCommentOld'], 5);
}
}
$pic_data['caption'] = '';
$pic_data['caption_text'] = $str;
$pic_data['title'] = $str;
$rowset[$ind] = $pic_data;
}
return $rowset;
}
示例12: readExif
/**
* Get associative array with exif info from a photo
*
* @param string $path Path to the photo.
* @return array Exif info in associative array.
*/
function readExif($path)
{
//include and call the exifixer script
require_once realpath(PHOTOQ_PATH . 'lib/exif/exif.php');
$fullexif = read_exif_data_raw($path, 0);
//we now retain only the useful (whatever it means ;-) ) info
$ifd0 = PhotoQExif::_filterUseless($fullexif['IFD0']);
$subIfd = PhotoQExif::_filterUseless($fullexif['SubIFD']);
$makerNote = $subIfd['MakerNote'];
unset($subIfd['MakerNote']);
$gps = PhotoQExif::_filterUseless($fullexif['GPS']);
//bring all the arrays to single dimension
$ifd0 = PhotoQHelper::flatten($ifd0);
$subIfd = PhotoQHelper::flatten($subIfd);
$makerNote = PhotoQHelper::flatten($makerNote);
$gps = PhotoQHelper::flatten($gps);
//and finally merge them into a single array
$exif = array_merge($ifd0, $subIfd, $makerNote, $gps);
//update discovered tags
PhotoQExif::_discoverTags($exif);
return $exif;
}
示例13: extract
static function extract($item)
{
$keys = array();
// Extract Latitude and Longitude from the image (if they exist).
if ($item->is_photo() && $item->mime_type == "image/jpeg") {
$data = array();
require_once MODPATH . "exif/lib/exif.php";
$exif_raw = read_exif_data_raw($item->file_path(), false);
if (isset($exif_raw['ValidEXIFData'])) {
foreach (self::_keys() as $field => $exifvar) {
if (isset($exif_raw[$exifvar[0]][$exifvar[1]])) {
$value = $exif_raw[$exifvar[0]][$exifvar[1]];
if (function_exists("mb_detect_encoding") && mb_detect_encoding($value) != "UTF-8") {
$value = utf8_encode($value);
}
$keys[$field] = Input::clean($value);
}
}
}
}
// If coordinates were extracted, save them to the database.
if (isset($keys["Latitude"]) && isset($keys["Longitude"])) {
$record = ORM::factory("exif_coordinate");
$record->item_id = $item->id;
$record->latitude = str_replace(",", ".", $keys["Latitude"]);
$record->longitude = str_replace(",", ".", $keys["Longitude"]);
// Represent N/S/E/W as postive and negative numbers
if (substr(strtoupper($keys["Latitude Reference"]), 0, 1) == "S") {
$record->latitude = "-" . $record->latitude;
}
if (substr(strtoupper($keys["Longitude Reference"]), 0, 1) == "W") {
$record->longitude = "-" . $record->longitude;
}
$record->save();
}
}
示例14: GetFileAngle
function GetFileAngle($filename)
{
$result = read_exif_data_raw($filename, 0);
$angle = 0;
if (isset($result['IFD0']['Orientation']))
{
if ($result['IFD0']['Orientation'] != "Normal (O deg)")
{
$angle_array = explode(" ", $result['IFD0']['Orientation']);
if ($angle_array[2] == "CCW")
$angle = 360 - $angle_array[0];
else
$angle = $angle_array[0];
}
}
if (isset($result['IFD1']['Orientation']))
{
if ($result['IFD1']['Orientation'] != "Normal (O deg)")
{
$angle_array = explode(" ", $result['IFD1']['Orientation']);
if ($angle_array[2] == "CCW")
$angle = 360 - $angle_array[0];
else
$angle = $angle_array[0];
}
else
$angle = 0;
}
if ($angle >= 360)
$angle = 0;
return $angle;
}
示例15: getOriginationTimestamp
function getOriginationTimestamp($file)
{
$rawExifData = array();
$rawExifData = read_exif_data_raw($file, false);
/*
* The method name indicates, that we want the earliest date available for the img.
* As of specs and practice with raw camera images and Adobe manipulated ones it seems,
* that SubIFD.DateTimeOriginal and SubIFD.DateTimeDigitized indicate creation time:
* both are set to shot time by cameras, scanners set only SubIFD.DateTimeDigitized.
* Adobe sets IFD0.DateTime to the last modification date/time. So we prefer creation
* dates.
*/
foreach (array('SubIFD.DateTimeOriginal', 'SubIFD.DateTimeDigitized', 'IFD0.DateTime') as $tag) {
$value = getExifValue($rawExifData, explode('.', $tag));
if (isset($value)) {
if (preg_match('#(\\d+):(\\d+):(\\d+)\\s+(\\d+):(\\d+):(\\d+)#', $value, $m)) {
$time = mktime((int) $m[4], (int) $m[5], (int) $m[6], (int) $m[2], (int) $m[3], (int) $m[1]);
} else {
if (preg_match('#(\\d+)-(\\d+)-(\\d+)T(\\d+):(\\d+):(\\d+)(([-+])(\\d+)(:(\\d+))?)?#', $value, $m)) {
$time = mktime((int) $m[4], (int) $m[5], (int) $m[6], (int) $m[2], (int) $m[3], (int) $m[1]);
}
}
if (!empty($time)) {
if (isset($m[8])) {
$offset = ((int) $m[9] * 60 + (isset($m[11]) ? (int) $m[11] : 0)) * 60;
if ($m[8] == '+') {
$time += $offset;
} else {
$time -= $offset;
}
}
return $time;
}
}
}
return null;
}