Automatically Rotate Avatar based on exif data
This commit.. * doesn't check if a local or uploaded file is square to give a user the option to crop square images * caches uploaded images to an initial temporary file (needed to fix orientation) * fixes orientation based on exif data * works for encrypted local images as well
This commit is contained in:
parent
d39216c5e7
commit
d0548b92c0
|
@ -46,7 +46,12 @@ class Controller {
|
||||||
if (isset($_POST['path'])) {
|
if (isset($_POST['path'])) {
|
||||||
$path = stripslashes($_POST['path']);
|
$path = stripslashes($_POST['path']);
|
||||||
$view = new \OC\Files\View('/'.$user.'/files');
|
$view = new \OC\Files\View('/'.$user.'/files');
|
||||||
$newAvatar = $view->file_get_contents($path);
|
$fileInfo = $view->getFileInfo($path);
|
||||||
|
if($fileInfo['encrypted'] === true) {
|
||||||
|
$fileName = $view->toTmpFile($path);
|
||||||
|
} else {
|
||||||
|
$fileName = $view->getLocalFile($path);
|
||||||
|
}
|
||||||
} elseif (!empty($_FILES)) {
|
} elseif (!empty($_FILES)) {
|
||||||
$files = $_FILES['files'];
|
$files = $_FILES['files'];
|
||||||
if (
|
if (
|
||||||
|
@ -54,7 +59,9 @@ class Controller {
|
||||||
is_uploaded_file($files['tmp_name'][0]) &&
|
is_uploaded_file($files['tmp_name'][0]) &&
|
||||||
!\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])
|
!\OC\Files\Filesystem::isFileBlacklisted($files['tmp_name'][0])
|
||||||
) {
|
) {
|
||||||
$newAvatar = file_get_contents($files['tmp_name'][0]);
|
\OC\Cache::set('avatar_upload', file_get_contents($files['tmp_name'][0]), 7200);
|
||||||
|
$view = new \OC\Files\View('/'.$user.'/cache');
|
||||||
|
$fileName = $view->getLocalFile('avatar_upload');
|
||||||
unlink($files['tmp_name'][0]);
|
unlink($files['tmp_name'][0]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -64,11 +71,9 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$avatar = new \OC_Avatar($user);
|
$image = new \OC_Image();
|
||||||
$avatar->set($newAvatar);
|
$image->loadFromFile($fileName);
|
||||||
\OC_JSON::success();
|
$image->fixOrientation();
|
||||||
} catch (\OC\NotSquareException $e) {
|
|
||||||
$image = new \OC_Image($newAvatar);
|
|
||||||
|
|
||||||
if ($image->valid()) {
|
if ($image->valid()) {
|
||||||
\OC\Cache::set('tmpavatar', $image->data(), 7200);
|
\OC\Cache::set('tmpavatar', $image->data(), 7200);
|
||||||
|
|
Loading…
Reference in New Issue