I found this plugin to fix orientation.
Will it work with gallery image upload ?
Or can you implement the case with exit orientation tag in CB uploads ?
Code:
/<?php
// ***********************************************************************************
// * *
// * Nifty iOS Image Fixer *
// * *
// ***********************************************************************************
// * *
// * @package plg_content_nifty_iosimagefixer *
// * @author In2 Computing Ltd. <support@in2computing.com> *
// * @copyright Copyright (c) 2017 In2 Computing Ltd. All Rights Reserved. *
// * @license GNU General Public Licence http://www.gnu.org/licenses/gpl-3.0.html *
// * @website https://in2computing.com/ *
// * @link https://in2computing.com/nifty-products/ios-image-fixer *
// * @version 1.0.0 *
// * *
// ***********************************************************************************
defined('_JEXEC') or die;
/**
* Nifty iOS Images Fixer content editing Plugin
*
* @package Joomla.Plugin
* @subpackage Content.Nifty_iosimagefixer
*/
jimport('joomla.filesystem.file');
class PlgContentNifty_iosimagefixer extends JPlugin
{
public function onContentAfterSave($context, $object_file, $isNew)
{
if($context === 'com_media.file' && $isNew)
{
if(!JFile::exists($object_file->filepath))
{
$this->LogError('onContentBeforeSave: File not found.');
return true;
}
return $this->fixImageRotation($object_file->filepath);
}
return true;
}
protected function fixImageRotation($file)
{
try
{
// new JImage object from image path
$image = new JImage($file);
// Read the exif data from the image
$exif = exif_read_data($file);
$rotate = 0;
// Get the angle to rotate the image based on the orientation
if (!empty($exif['Orientation']))
{
// Based on the orientation of time image, assign the rotation angle.
switch ($exif['Orientation'])
{
case 3:
$rotate = 180;
break;
case 6:
$rotate = -90;
break;
case 8:
$rotate = 90;
break;
}
// Rotate the image appropriately
$newImage = $image->rotate($rotate);
// Overwrite the old image with new image
if (!$newImage->toFile($file))
{
$this->LogError("Unable to overwrite '" . $file . "'");
return false;
}
}
else
{
// No exif data found.
return true;
}
}
catch(exception $ex)
{
$this->LogError($ex->getMessage());
return false;
}
}
protected function LogError($msg)
{
// Include the JLog class.
jimport('joomla.log.log');
// Initialise a basic logger with no options (once only).
JLog::addLogger(array());
// Log the error.
JLog::add('plg_content_nifty_iosimagefixer->nifty_iosimagefixer.php: ' . $msg, JLog::ERROR);
}
}