×
Blue Eagle (1.5.0) for K5.1 is released (20 Jul 2018)

Please update the Kunena Blue Eagle to 1.5.0 if you use Kunena 5.1.
We made several bug fixes and improvements. Also Blue Eagle has now all the features from Crypsis.
Download: www.kunena.org/download/templates/category/blue-eagle-5

Solved Image orientation on upload - K 4.06 with Crypsis

More
2 years 9 months 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
2 years 9 months 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
2 years 9 months 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
2 years 9 months 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.085 seconds