调整上传的elFinder图像的大小



我希望在上传过程中调整不同的图像大小,而不是200x100。然而,我找不到任何相关的文件来进行此调整。

经过一些搜索,我看到很多人告诉其他人查看connector.php。在这个文件中,我需要沿着以下几行传递一些信息:

$opts = array(
            'bind' => array(
                'upload resize' => array($this, 'myResize')
            ),
            'roots' => array(
                array(...)
            )
        );
/**
     * Upload/resize callback catcher, resizes image to 320x240px/240x320px respectively, keeps ratio
     *
     * @param  string   $cmd       command name
     * @param  array    $result    command result
     * @param  array    $args      command arguments from client
     * @param  object   $elfinder  elFinder instance
     * @return true     Forces elFinder to sync all events
     * */
    public function myResize($cmd, $result, $args, $elfinder) {
        $files = $result['added'];
        foreach ($files as $file) {
            $arg = array(
                'target' => $file['hash'],
                'width' => 320,
                'height' => 320,
                'x' => 0,
                'y' => 0,
                'mode' => 'propresize',
                'degree' => 0
            );
            $elfinder->exec('resize', $arg);
        }
        return true;
    }

我最大的问题是:

我该把这个函数放在哪里?我正在使用Symfony2的(FM)ElfinderBundle。

有两种方法可以解决这个问题。

  1. 将您的函数(myResize)放在connector.php中:

    公共函数myResze($cmd、$result、$args、$elfinder){//其他代码}

然后将"绑定"设置为:

'bind' => array(
    'upload resize' => 'myResize');
  1. 在connector.php中定义您的类,并获取一个用于"bind"的实例。示例:
类className{//其他代码公共函数myResize($cmd、$result、$args、$elfinder){//其他代码}}

从这个类创建一个对象之后:

$obj = new className();

然后将"绑定"设置为:

'bind' => array(
    'upload resize' => array($obj, 'myResize'));

此示例对您很有用:https://github.com/Studio-42/elFinder/wiki/Logging

最新更新