port of reds geotag feature

This commit is contained in:
rabuzarus 2015-09-30 00:19:54 +02:00
parent a102fd83e8
commit c775d6885b
4 changed files with 97 additions and 32 deletions

View file

@ -345,38 +345,37 @@ class Photo {
}
public function orient($filename) {
if ($this->is_imagick()) {
// based off comment on http://php.net/manual/en/imagick.getimageorientation.php
$orientation = $this->image->getImageOrientation();
switch ($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$this->image->rotateimage("#000", 180);
break;
case imagick::ORIENTATION_RIGHTTOP:
$this->image->rotateimage("#000", 90);
break;
case imagick::ORIENTATION_LEFTBOTTOM:
$this->image->rotateimage("#000", -90);
break;
}
if ($this->is_imagick()) {
// based off comment on http://php.net/manual/en/imagick.getimageorientation.php
$orientation = $this->image->getImageOrientation();
switch ($orientation) {
case imagick::ORIENTATION_BOTTOMRIGHT:
$this->image->rotateimage("#000", 180);
break;
case imagick::ORIENTATION_RIGHTTOP:
$this->image->rotateimage("#000", 90);
break;
case imagick::ORIENTATION_LEFTBOTTOM:
$this->image->rotateimage("#000", -90);
break;
}
$this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
return TRUE;
}
$this->image->setImageOrientation(imagick::ORIENTATION_TOPLEFT);
return TRUE;
}
// based off comment on http://php.net/manual/en/function.imagerotate.php
if(!$this->is_valid())
return FALSE;
return FALSE;
if( (! function_exists('exif_read_data')) || ($this->getType() !== 'image/jpeg') )
return;
return;
$exif = @exif_read_data($filename);
$exif = @exif_read_data($filename,null,true);
if(! $exif)
return;
if(! $exif)
return;
$ort = $exif['Orientation'];
$ort = $exif['IFD0']['Orientation'];
switch($ort)
{
@ -413,6 +412,10 @@ class Photo {
$this->rotate(90);
break;
}
// logger('exif: ' . print_r($exif,true));
return $exif;
}

View file

@ -23,6 +23,7 @@ function get_features() {
t('General Features'),
//array('expire', t('Content Expiration'), t('Remove old posts/comments after a period of time')),
array('multi_profiles', t('Multiple Profiles'), t('Ability to create multiple profiles')),
array('photo_location', t('Photo Location'), t('Photo metadata is normally stripped. This extracts the location (if present) prior to stripping metadata and links it to a map.'),false),
),
// Post composition

27
include/photos.php Normal file
View file

@ -0,0 +1,27 @@
<?php
/**
* @file include/photos.php
* @brief Functions related to photo handling.
*/
function getGps($exifCoord, $hemi) {
$degrees = count($exifCoord) > 0 ? gps2Num($exifCoord[0]) : 0;
$minutes = count($exifCoord) > 1 ? gps2Num($exifCoord[1]) : 0;
$seconds = count($exifCoord) > 2 ? gps2Num($exifCoord[2]) : 0;
$flip = ($hemi == 'W' or $hemi == 'S') ? -1 : 1;
return floatval($flip * ($degrees + ($minutes / 60) + ($seconds / 3600)));
}
function gps2Num($coordPart) {
$parts = explode('/', $coordPart);
if (count($parts) <= 0)
return 0;
if (count($parts) == 1)
return $parts[0];
return floatval($parts[0]) / floatval($parts[1]);
}