SilverStripe CropperField 选项

SilverStripe CropperField options

我正在使用 SilverStripe Cropperfield:https://github.com/willmorgan/silverstripe-cropperfield

应该有一种方法可以设置 aspect_ratio 选项来将 cropperbox 设置为特定大小。然而,文档并不完全清楚将此选项放在哪里。

在哪里可以设置选项?

在代码中...

https://github.com/willmorgan/silverstripe-cropperfield/blob/master/code/CropperField.php#L244

...这个选项追溯到这个静态数组...

https://github.com/willmorgan/silverstripe-cropperfield/blob/master/code/CropperField.php#L32

...您可以在构建时设置 - 但这不是您要问的。在 silverstripe 中,任何静态数组都可以在代码中设置,所以我建议您将其添加到 _confip.php

Config::inst()->update('CropperField', 'default_options',array(
        'aspect_ratio' => <SET ME HERE>,
        'crop_min_width' => 256,
        'crop_min_height' => 256,
        'crop_max_width' => null,
        'crop_max_height' => null,
        'generated_max_width' => 512,
        'generated_max_height' => 512,
));

确保设置所需的纵横比

构造函数的第四个选项,当你实例化字段时。

https://github.com/willmorgan/silverstripe-cropperfield/blob/master/code/CropperField.php#L89

希望本模块对您有所帮助!