level51 / silverstripe-cloudinary
SilverStripe的Cloudinary图像处理和上传字段
2.0.0
2023-09-16 00:00 UTC
Requires
- php: >=8.0
- ext-json: *
- cloudinary/cloudinary_php: ^2
- nesbot/carbon: ^2
- silverstripe/framework: ^5
README
添加了一个Level51\Cloudinary\Image
数据对象和一个使用Cloudinary的javascript上传小部件的适当上传器。
安装
composer require level51/silverstripe-cloudinary
设置
您必须定义一些强制性的配置才能开始
Level51\Cloudinary\Cloudinary: cloud_name: String, mandatory api_key: String, mandatory api_secret: String, mandatory upload_preset: String, mandatory if unsigned, optional if signed # https://cloudinary.com/documentation/upload_widget#look_and_feel_customization theme: default 'white', # https://cloudinary.com/documentation/upload_widget#signed_uploads use_signed: true # https://cloudinary.com/documentation/admin_api#delete_all_or_selected_resources image_type: 'private' # Whether to show/hide the remove button show_remove: false # Whether to append the g_custom option or not use_custom_gravity: true # Allowed file extensions, optional, defaults to ['png', 'gif', 'jpeg'] # Note that the extensions can also be limited per instance using `setAllowedExtensions` allowed_extensions: ['png', 'gif', 'jpeg']
用法
private static $has_one = [ 'Image' => \Level51\Cloudinary\Image::class ]; private static $has_many = [ 'Images' => Image::class ]; public function getCMSFields() { $fields = parent::getCMSFields(); $fields->addFieldsToTab( 'Root.Main', [ \Level51\Cloudinary\UploadField::create('Image', $this->fieldLabel('Image')), // ->setRatio(16 / 9) // ->disableCropping() // ->setFolderName('path/to/destination') // ->setAllowedExtensions(['jpg']) \Level51\Cloudinary\MultiUploadField::create('Images', $this->fieldLabel('Images')) // ->setAllowedMaxFileNumber(5) ] ); return $fields; }
// In templates $Image // With transormations $Image.FillMax(1920,1080) // With effect filters $Image.Grayscale.FillMax(1920,1080)
查看\Level51\Cloudinary\Image类中可用的转换和效果。
功能
- 使用javascript上传小部件的UploadField - 因此直接上传到Cloudinary
- 将相关信息存储在Level51\Cloudinary\Image对象中
扩展
如果您需要更多字段,只需通过数据扩展扩展Level51\Cloudinary\Image类。要注入Cloudinary在上传过程中返回的信息,为Level51\Cloudinary\UploadController创建另一个扩展并使用两个扩展钩子之一onBeforeImageCreated
或onAfterImageCreated
。两者都传递图像对象,在第一次写入之前或之后。
维护者
- Daniel Kliemsch dk@lvl51.de