ckfinder image resize

David Verhulst picture David Verhulst · Jun 17, 2010 · Viewed 8.3k times · Source

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

Answer

Micah Murray picture Micah Murray · Aug 10, 2012

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.