-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplugin.php
77 lines (66 loc) · 2.61 KB
/
plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Plugin.php
*
* PHP version 7
*
* @category Orientator
* @package Xpressengine\Plugins\Orientator
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
namespace Xpressengine\Plugins\Orientator;
use Xpressengine\Plugin\AbstractPlugin;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Xpressengine\Media\Models\Media;
use Intervention\Image\ImageManager;
/**
* Class Plugin
*
* @category Orientator
* @package Xpressengine\Plugins\Orientator
* @author XE Developers <developers@xpressengine.com>
* @copyright 2019 Copyright XEHub Corp. <https://www.xehub.io>
* @license http://www.gnu.org/licenses/lgpl-3.0-standalone.html LGPL
* @link https://xpressengine.io
*/
class Plugin extends AbstractPlugin
{
public function boot()
{
intercept('XeStorage@upload', 'orientator.orientate', function ($target, $uploaded, $path, $name = null, $disk = null, $user = null) {
/** @var UploadedFile $uploaded */
if ($uploaded->isValid()) {
$mime = $uploaded->getMimeType();
/** @var \Xpressengine\Media\Handlers\ImageHandler $imageHandler */
$imageHandler = app('xe.media')->getHandler(Media::TYPE_IMAGE);
// todo: 모바일 판단여부 적용 or 무시 (ex. app('request')->isMobile())
if ($imageHandler->isAvailable($mime)) {
$manager = new ImageManager();
$image = $manager->make($uploaded);
if (isset($image->exif()['Orientation'])) {
$content = $image->orientate()->encode()->getEncoded();
file_put_contents($uploaded->getPathname(), $content);
$uploaded = new UploadedFile(
$uploaded->getPathname(),
$uploaded->getClientOriginalName(),
$uploaded->getClientMimeType(),
strlen($content)
);
}
}
}
return $target($uploaded, $path, $name, $disk, $user);
});
}
public function activate($installedVersion = null)
{
if (!function_exists('exif_read_data')) {
throw new \Intervention\Image\Exception\NotSupportedException(
"Reading Exif data is not supported by this PHP installation."
);
}
}
}