diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2013-12-29 20:45:58 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2013-12-29 20:45:58 -0200 |
commit | 97e689213ff4e829f251af526ed4e796a3cc2b71 (patch) | |
tree | b04d03ec56305041216b72328fc9b5afde27bc76 /mod/lightpics/lib/exif.php | |
parent | 0ab6351abb7a602d96c62b0ad35413c88113a6cf (diff) | |
parent | 69e2d8c5d8732042c9319aef1fdea45a82b63e42 (diff) | |
download | elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.gz elgg-97e689213ff4e829f251af526ed4e796a3cc2b71.tar.bz2 |
Merge branch 'master' into saravea
Conflicts:
.gitmodules
mod/admins
mod/assemblies
mod/audio_html5
mod/beechat
mod/crud
mod/elgg-activitystreams
mod/elggman
mod/elggpg
mod/favorites
mod/federated-objects
mod/friendly_time
mod/group_alias
mod/group_operators
mod/languages
mod/lightpics
mod/openid_client
mod/spotlight
mod/suicide
mod/tasks
mod/videolist
Diffstat (limited to 'mod/lightpics/lib/exif.php')
-rw-r--r-- | mod/lightpics/lib/exif.php | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/mod/lightpics/lib/exif.php b/mod/lightpics/lib/exif.php new file mode 100644 index 000000000..46a73e920 --- /dev/null +++ b/mod/lightpics/lib/exif.php @@ -0,0 +1,110 @@ +<?php +/** + * Exif Processing Library + * + * @package TidypicsExif + */ + +/** + * Pull EXIF data from image file + * + * @param TidypicsImage $image + */ +function td_get_exif($image) { + + // catch for those who don't have exif module loaded + if (!is_callable('exif_read_data')) { + return; + } + + $mime = $image->mimetype; + if ($mime != 'image/jpeg' && $mime != 'image/pjpeg') { + return; + } + + $filename = $image->getFilenameOnFilestore(); + $exif = exif_read_data($filename, 'IFD0,EXIF', true); + if (is_array($exif) && isset($exif['EXIF'])) { + $data = array_merge($exif['IFD0'], $exif['EXIF']); + foreach ($data as $key => $value) { + if (is_string($value)) { + // there are sometimes unicode characters that cause problems with serialize + $data[$key] = preg_replace( '/[^[:print:]]/', '', $value); + } + } + $image->tp_exif = serialize($data); + } +} + +/** + * Grab array of EXIF data for display + * + * @param TidypicsImage $image + * @return array|false + */ +function tp_exif_formatted($image) { + + $exif = $image->tp_exif; + if (!$exif) { + return false; + } + + $exif = unserialize($exif); + + $model = $exif['Model']; + if (!$model) { + $model = "N/A"; + } + $exif_data['Model'] = $model; + + $exposure = $exif['ExposureTime']; + if (!$exposure) { + $exposure = "N/A"; + } + $exif_data['Shutter'] = $exposure; + + //got the code snippet below from http://www.zenphoto.org/support/topic.php?id=17 + //convert the raw values to understandible values + $Fnumber = explode("/", $exif['FNumber']); + if ($Fnumber[1] != 0) { + $Fnumber = $Fnumber[0] / $Fnumber[1]; + } else { + $Fnumber = 0; + } + if (!$Fnumber) { + $Fnumber = "N/A"; + } else { + $Fnumber = "f/$Fnumber"; + } + $exif_data['Aperture'] = $Fnumber; + + $iso = $exif['ISOSpeedRatings']; + if (!$iso) { + $iso = "N/A"; + } + $exif_data['ISO Speed'] = $iso; + + $Focal = explode("/", $exif['FocalLength']); + if ($Focal[1] != 0) { + $Focal = $Focal[0] / $Focal[1]; + } else { + $Focal = 0; + } + if (!$Focal || round($Focal) == "0") { + $Focal = 0; + } + if (round($Focal) == 0) { + $Focal = "N/A"; + } else { + $Focal = round($Focal) . "mm"; + } + $exif_data['Focal Length'] = $Focal; + + $captured = $exif['DateTime']; + if (!$captured) { + $captured = "N/A"; + } + $exif_data['Captured'] = $captured; + + return $exif_data; +} |