Rotate image according to EXIF orientation not working from a plugin I am using a front-end form to upload images and store them as assets on an amazon S3 bucket.

My server has imagick installed an uses it and in my config I have "rotateImagesOnUploadByExifData" set to true.

When uploading an image I use this code to get the image and store it as an asset:

$file = UploadedFile::getInstanceByName('file');
$tempFilePath = $file-&gt;getTempName();
$folder = craft()-&gt;assets-&gt;findFolder(array(
    'sourceId' =&gt; craft()-&gt;config-&gt;get('assetSourceId', 'myPlugin'),
    'id'       =&gt; craft()-&gt;config-&gt;get('assetFolderId', 'myPlugin')
));            

// Turn the file into a managed asset within that folder
$response = craft()-&gt;assets-&gt;insertFileByLocalPath(
    $tempFilePath,
    $file-&gt;getName(),
    $folder-&gt;id,
    AssetConflictResolution::KeepBoth
);


Everything is working as expected, an asset is created, files get transferred to Amazon S3 bucket, but when transforming the image it shows rotated. 

So I investigated:
The function 'insertFileByLocalPath' calls the function 'insertFileByPath' 

In its turn this function performs the following check:

if (IOHelper::getFileKind(IOHelper::getExtension($localFilePath)) == 'image'
            &amp;&amp; ImageHelper::isImageManipulatable(IOHelper::getExtension($localFilePath))
)
{
    craft()-&gt;images-&gt;cleanImage($localFilePath);
}


The cleanImage function should rotate the image and strip the exif data afterwards.

But since these functions work with the temporary file name (which is e.g. "/tmp/phpZB1A8y") this does not pass the test in the previous code. (it is not recognized as an image filename since it has no extension)

Any idea how I could work around this issue?
The best way to do this would be to follow the same flow that Craft does - clean the filename, move to a temporary location, operate from there and afterwards delete the temporary file.

Craft has an example in it's codebase to help you out. Just remember to delete the temp file afterwards.