×
Blue Eagle 1.5.2 Released (11 Dec 2018)

The Kunena team has announce the arrival of Kunena Blue Eagle 1.5.2 which is now available for download as a native Joomla extension for Kunena 5.1. This version addresses most of the issues that were discovered in K 1.5.1 and issues discovered during the development stages of K 1.5.2.

Solved Image orientation on upload - K 4.06 with Crypsis

More
3 years 1 month ago #1 by WolfgangOWL
Hello folks,

I recently updated from K 4.05 with Blue Eagle template to 4.06 with Crypsis. I modified the upload.php to change the orientation of uploaded images with portrait orientation using the orientation tag of jpg files. This worked fine until before the update. The same modification applied after the update has no effect at all. Can anyone help me with this?

Thanks in advance,
Wolfgang

Please Log in or Create an account to join the conversation.

More
3 years 1 month ago #2 by WolfgangOWL
I found out the reason. Crypsis uses the ajaxUpload function for file uploads. After applying the image rotation there it works fine.

Please Log in or Create an account to join the conversation.

More
3 years 1 month ago #3 by 810
good, could you add the code, how to change it, maybe someone else can use it.

Please Log in or Create an account to join the conversation.

More
3 years 1 month ago #4 by WolfgangOWL

810 wrote: good, could you add the code, how to change it, maybe someone else can use it.


Shure I can.

This is the function which does the image rotation:
    function correctImageOrientation($filename)
    {
        $testForJpg = getimagesize($filename);
 
        if ($testForJpg[2] == 2)
        {
            if (function_exists('exif_read_data')) 
            {
                $deg  = 0;
                $exif = exif_read_data($filename);
 
                if ($exif && isset($exif['Orientation'])) 
                {
                    $orientation = $exif['Orientation'];
 
                    if ($orientation != 1)
                    {
                        $img = imagecreatefromjpeg($filename);
 
                        switch ($orientation) 
                        {
                            case 3:
                            case 4: $deg = 180;
                                    break;
                            case 5:
                            case 6: $deg = 270;
                                    break;
                            case 7:
                            case 8: $deg = 90;
                                    break;
                        }
                    }
                }
 
                if ($deg > 0) 
                {
                    $img = imagerotate($img, $deg, 0);        
                    imagejpeg($img, $filename, 95);
                } 
            }
        }
    }

This code must be placed in function ajaxUpload above of
}
catch (Exception $exception)
{
}
// get filename from stream
$meta_data = stream_get_meta_data($out);
$filename  = $meta_data["uri"];
$this->correctImageOrientation($filename);

And this must be placed in function upload above of
if (!KunenaFile::copy($file->tmp_name, $file->destination))
{
throw new RuntimeException(JText::_('COM_KUNENA_UPLOAD_ERROR_FILE_RIGHT_MEDIA_DIR'), 500);
}
$this->correctImageOrientation($file->tmp_name);

Please Log in or Create an account to join the conversation.

  • Not Allowed: to create new topic.
  • Not Allowed: to reply.
  • Not Allowed: to add attachements.
  • Not Allowed: to edit your message.
Time to create page: 0.098 seconds