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->getTempName();
$folder = craft()->assets->findFolder(array(
'sourceId' => craft()->config->get('assetSourceId', 'myPlugin'),
'id' => craft()->config->get('assetFolderId', 'myPlugin')
));
// Turn the file into a managed asset within that folder
$response = craft()->assets->insertFileByLocalPath(
$tempFilePath,
$file->getName(),
$folder->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'
&& ImageHelper::isImageManipulatable(IOHelper::getExtension($localFilePath))
)
{
craft()->images->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?