Yii 1.1: nava-jcrop

very easy to upload image and crop it

This extension is a wrapper of JavaScript-Load-Image

It's very easy to use, was made because I tried jcrop, jii-crop but it is not what I need.


Yii 1.1.x or above


extract all file to application/extensions

View file:

$this->widget('ext.NavaJcrop.ImageJcrop', array(
    'config' => array(
        'image'=>$model->image_url,//required, all field below are not required.
                'style'=>'margin-left: 5px;',
                'style'=>'margin-left: 5px;',
                'style'=>'margin-left: 5px;',
            'resultStyle'=>'position: fixed;top: 50px;max-width:350px;max-height:350px;z-index: 9999;',
        'callBack'=> array(

You can change the callBack:


and the javascript for it:

function doSomething(obj,res){ //the 'obj' is IMG tag, 'res' is base64image
        cache: false,
        type: 'post',
        url: '<?php echo Yii::app()->createUrl('site/upload');?>',
        data: 'image='+res,
        success: function(){

Controller code to upload this image:

public function actionUpload(){
    $model = new Model();
        $img = $_POST['image'];
        if($img != '/img/noimage.png' && $img != $model->image_url){
            $img = str_replace('data:image/png;base64,', '', $img);
            $img = str_replace(' ', '+', $img);
            $data = base64_decode($img);
            $file = '/uploads/images/'.$model->id.'.jpg';
            $model->image_url = Yii::app()->request->hostInfo.'/'.Yii::app()->baseUrl.$file;
            file_put_contents(Yii::getPathOfAlias('webroot').$file, $data);


Version 0.2

  • Fixed "Undefined variable: imageWidth" even you dont set 'options' in view's 'config'. Thank m3hr@n
  • Do not need to click Edit button.




Total 2 comments

#19828 report it
bhavesh vaghela at 2016/04/08 04:34pm
How to use with multiple images

I has been trying to make cropping on multiple images on same pages, but it doesn't work. It works on single image only.

#18215 report it
m3hr@n at 2014/09/28 04:32am
Good job

Its great man. by the way there is a little bug in your ImageJcrop.php.

you have to close the first if block in init() right after this:

$options = $this->config['options'];// line 60

I mean move '}' from line 86 to line 61. something like this:

    $options = $this->config['options'];
}// moved from line 86 to 61

then you will nerver see error like "Undefined variable: imageWidth" even you dont set 'options' in view's 'config'.

Leave a comment

Please to leave your comment.

Create extension