简体   繁体   English

ckeditor-ckfinder 上传图像的默认属性(宽度和高度)

[英]ckeditor-ckfinder default attributes (width and height) to uploaded images

When I upload images using ckfinder in the ckeditor the image displays nicely using css width & height.当我在 ckeditor 中使用 ckfinder 上传图像时,图像使用 css 宽度和高度很好地显示。 I would like images to have default width and height attributes.我希望图像具有默认的宽度和高度属性。 How can I accomplish that?我怎样才能做到这一点?

Set the default width and height while clicking "ok" button.单击“确定”按钮时设置默认宽度和高度。 Replace the user entered height & width values with default height & width (Override "OnOK" Function)用默认的高度和宽度替换用户输入的高度和宽度值(覆盖“OnOK”功能)

In config.js在 config.js 中

 CKEDITOR.on('dialogDefinition', function (ev) {

    var dialogName = ev.data.name,
        dialogDefinition = ev.data.definition;

    if (dialogName == 'image') {
        var onOk = dialogDefinition.onOk;

        dialogDefinition.onOk = function (e) {
            var width = this.getContentElement('info', 'txtWidth');
            width.setValue('200');//Set Default Width

            var height = this.getContentElement('info', 'txtHeight');
            height.setValue('200');////Set Default height

            onOk && onOk.apply(this, e);
        };
    }
});

If I'm not mistaken, CKFinder just uploads the file to the server, and does not changes its resolution!如果我没记错的话,CKFinder 只是将文件上传到服务器,并不会更改其分辨率! You can however, use/create a plugin for CKEditor to change the image width & height when using the image dialog of CKEditor!但是,您可以在使用 CKEditor 的图像对话框时使用/创建 CKEditor 插件来更改图像宽度和高度!

Btw: That dialog allows you to change the width and height of the selected image before placing it in your "document" !顺便说一句:该对话框允许您在将所选图像放入“文档”之前更改其宽度和高度! The values that are placed there by CKEditor are the real width & height of the selected image! CKEditor 放置在那里的值是所选图像的实际宽度和高度!

查看_samples文件夹中的output_html.html

In the image.js which is in plugins/image/dialogs folder of the CKEDITORCKEDITOR 的plugins/image/ dialogs文件夹中的 image.js

there are two lines:有两行:

d&&d.setValue(b.$.width);
e&&e.setValue(b.$.height);

If you change b.$.width and b.$.height with numbers or null , you will have default values upon upload of any image size.如果您使用数字或null更改b.$.widthb.$.height ,则上传任何图像大小时都将具有默认值。

For example:例如:

d&&d.setValue(600);
e&&e.setValue(null);

Will insert an image with 600px width and proportional height.将插入宽度为 600 像素且高度成比例的图像。 Remember to duplicate your image.js before editing it.请记住在编辑之前复制您的image.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM