-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCropper.php
executable file
·59 lines (54 loc) · 1.42 KB
/
Cropper.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
<?php
namespace yidashi\webuploader;
use Yii;
use yii\helpers\Html;
/**
* 图片裁剪上传
* 为了能够预览它,需要在你想要预览的地方放下如下代码:
* <div class="fileupload fileupload-new">
* <div class="img-preview"></div>
* </div>
* 在你想要出现“选择文件”的地方,放下如下代码:
* <?= Cropper::widget() ?>
*
* @author Shiyang <[email protected]>
*/
class Cropper extends Webuploader
{
/**
* @inheritdoc
*/
public function init()
{
$this->driver = 'local';
parent::init();
}
/**
* @inheritdoc
*/
public function run()
{
$web = rtrim(\Yii::getAlias('@static'), '/');
$value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
$image = $value ? Html::img(
strpos($value, 'http:') === false ? (\Yii::getAlias('@static') . '/' . $value) : $value,
['width'=>$this->options['previewWidth'],'height'=>$this->options['previewHeight']]
) : '';
$this->registerClientScript();
return $this->render('cropper', [
'options' => $this->options,
'image' => $image,
'server' => $this->server,
'hiddenInput' => $this->hiddenInput,
'web' => $web
]);
}
/**
* Registers Webuploader assets
*/
protected function registerClientScript()
{
$view = $this->getView();
CropperAsset::register($view);
}
}