ckfinder image resize

不打扰是莪最后的温柔 提交于 2019-12-01 16:55:16

问题


After selecting or uploading an image with the ckfinder, the user can change the width and height. I want it to automatically resize the image to the width and height the user sets. Is that possible?

I thaught that the ajax image resizer would fix that but can't get it to work. Somebody has experience with an automatic width and height resize-plugin?

In my config file of ckfinder I've got:

include_once "plugins/imageresize/plugin.php";

in the config.js I've got:

CKFinder.customConfig = function( config )
{
 config.extraPlugins = 'imageresize';
};

回答1:


In the past, I've pre-defined an auto resize value to a specific folder in ckFinder so that any image a user uploads to that folder is resized. I do that by adding a little code to the config.php file like this:

// This next block sets the default max image size and quality
$config['Images'] = Array(
        'maxWidth' => 1600,
        'maxHeight' => 1200,
        'quality' => 80);

// Here we override those settings for a given folder
if(isset($_GET['currentFolder']) && urldecode($_GET['currentFolder']) == '/some-folder-name/'){
    $config['Images']['maxWidth'] = 150;
    $config['Images']['maxHeight'] = 150;
}

I would suspect you could do a similar hack, perhaps using $_SESSION values. Have your user select the auto-resize values they need and save it in their $_SESSION. Then in your config file, look for that session value. Something like:

if(isset($_SESSION['resize_w']) && isset($_SESSION['resize_h']) ){
    $config['Images']['maxWidth'] = $_SESSION['resize_w'];
    $config['Images']['maxHeight'] = $_SESSION['resize_h'];
}

Note that you'll need to call session_start() in your config.php file if you haven't already.




回答2:


Ckeditor does't resize the image,it only change the height and width value. instead of resizing the image,Set the default width and height while clicking "ok" button. Here I replace the user entered height & width values with default height & width.

 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);
        };
    }
});



回答3:


In the "config.ascx" file change the value of variable as

Images.MaxWidth = 0; 
Images.MaxHeight = 0;
Images.Quality = 100;


来源:https://stackoverflow.com/questions/3057938/ckfinder-image-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!