Skip to content

Commit

Permalink
Added WiP feature to file upload, to do EXIF orientation check on
Browse files Browse the repository at this point in the history
images, and rotate image if necessary.
  • Loading branch information
cheesegrits committed Aug 27, 2015
1 parent dfa7c11 commit c73254d
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 27 deletions.
49 changes: 42 additions & 7 deletions components/com_fabrik/helpers/image.php
Expand Up @@ -240,7 +240,7 @@ public function getImgType($filename)
public function resize($maxWidth, $maxHeight, $origFile, $destFile, $quality = 100)
{
}

/**
* Grab an image from a remote URI and store in cache, then serve cached image
*
Expand Down Expand Up @@ -455,14 +455,19 @@ public function imageToFile($destCropFile, $image)
* Rotate an image
*
* @param string $source filepath
* @param string $dest output path
* @param string $dest output path, if empty defaults to source
* @param double $degrees number of degrees to rotate
*
* @return array (image object, rotated images width, rotated images height)
*/

public function rotate($source, $dest = '', $degrees = 0)
{
if (empty($dest))
{
$dest = $source;
}

$source = $this->imageCreateFrom($source);
$app = JFactory::getApplication();

Expand All @@ -474,14 +479,44 @@ public function rotate($source, $dest = '', $degrees = 0)
$app->enqueueMessage('Image rotation failed', 'notice');
}

if ($dest != '')
{
$this->imageToFile($dest, $rotate);
list($width, $height) = getimagesize($dest);
}
$this->imageToFile($dest, $rotate);
list($width, $height) = getimagesize($dest);

return array($rotate, $width, $height);
}

/*
* Check for EXIF orientation data, and rotate image accordingly
*
* @param string path to image file
*/
public function rotateImageFromExif($src, $dest)
{
if (function_exists('exif_read_data')) {
$exif = exif_read_data($src);
if($exif && isset($exif['Orientation'])) {
$orientation = $exif['Orientation'];
if($orientation != 1){
$deg = 0;
switch ($orientation) {
case 3:
$deg = 180;
break;
case 6:
$deg = 270;
break;
case 8:
$deg = 90;
break;
}
if ($deg) {
self::rotate($src, $dest, $deg);
}
}
}
}
}


/**
* Scale an image
Expand Down
4 changes: 1 addition & 3 deletions components/com_fabrik/helpers/parent.php
Expand Up @@ -55,7 +55,7 @@ class FabrikWorker
*
* @var string
*/
protected $image_extensions_eregi = 'bmp|gif|jpg|jpeg|png';
static protected $image_extensions_eregi = 'bmp|gif|jpg|jpeg|png';

/**
* Audio file extensions
Expand Down Expand Up @@ -132,8 +132,6 @@ public static function isViewType($view)
*
* @param string $file Filename
*
* @deprecated - doesn't seem to be used
*
* @return bool
*/

Expand Down
42 changes: 25 additions & 17 deletions plugins/fabrik_element/fileupload/fileupload.php
Expand Up @@ -1853,29 +1853,37 @@ protected function _processIndUpload(&$file, $myFileDir = '', $repeatGroupCounte
jimport('joomla.filesystem.path');
$storage->setPermissions($filePath);

// $$$ hugh @TODO - shouldn't we check to see if it's actually an image before we do any of this stuff???
// Resize main image
$oImage = FabimageHelper::loadLib($params->get('image_library'));
$oImage->setStorage($storage);
$mainWidth = $params->get('fu_main_max_width', '');
$mainHeight = $params->get('fu_main_max_height', '');

if ($mainWidth != '' || $mainHeight != '')
if (FabrikWorker::isImageExtension($filePath))
{
// $$$ rob ensure that both values are integers otherwise resize fails
if ($mainHeight == '')
// Resize main image
$oImage = FabimageHelper::loadLib($params->get('image_library'));
$oImage->setStorage($storage);

if ($params->get('upload_use_wip', '0') == '1')
{
$mainHeight = (int) $mainWidth;
$oImage->rotateImageFromExif($filePath, '');
}

if ($mainWidth == '')

$mainWidth = $params->get('fu_main_max_width', '');
$mainHeight = $params->get('fu_main_max_height', '');

if ($mainWidth != '' || $mainHeight != '')
{
$mainWidth = (int) $mainHeight;
// $$$ rob ensure that both values are integers otherwise resize fails
if ($mainHeight == '')
{
$mainHeight = (int) $mainWidth;
}

if ($mainWidth == '')
{
$mainWidth = (int) $mainHeight;
}

$oImage->resize($mainWidth, $mainHeight, $filePath, $filePath, $quality);
}

$oImage->resize($mainWidth, $mainHeight, $filePath, $filePath, $quality);
}

// $$$ hugh - if it's a PDF, make sure option is set to attempt PDF thumb
$make_thumbnail = $params->get('make_thumbnail') == '1' ? true : false;

Expand Down

0 comments on commit c73254d

Please sign in to comment.