2

I see Lot's of image Crop example But i'm not find like what's i want. So i post in Stackoverflow.

A complete script in Codeigniter FrameWork as view as like
1. Click upload and select .jpg/.png file
2. auto upload in server and Show like

https://i.sstatic.net/VTtO5.png
3. After upload User crop Profile Pic preDifiend Size.
4. and save in my DB.

I'm unable to ajax. Plz.. If you have complete this Provide me.

Ebrahim Khalil

1

1 Answer 1

3

I am using JCrop Plugin, Check out their PHP cropping example. Basically what happens when you select are to crop, It will be saved in X,Y for co-ordinates and H,W for height and width.

Codeigniter's image_lib gives simple way to crop or resize image. Read the docs for that ..

My code Snippet :

        //crop it
        $data['x'] = $this->input->post('x');
        $data['y'] = $this->input->post('y');
        $data['w'] = $this->input->post('w');
        $data['h'] = $this->input->post('h');

        $config['image_library'] = 'gd2';
        //$path =  'uploads/apache.jpg';
        $config['source_image'] = 'uploads/'.$data['user_data']['img_link']; //http://localhost/resume/uploads/apache.jpg
       // $config['create_thumb'] = TRUE;
        //$config['new_image'] = './uploads/new_image.jpg';
        $config['maintain_ratio'] = FALSE;
        $config['width']  = $data['w'];
        $config['height'] = $data['h'];
        $config['x_axis'] = $data['x'];
        $config['y_axis'] = $data['y'];

        $this->load->library('image_lib', $config); 

        if(!$this->image_lib->crop())
        {
            echo $this->image_lib->display_errors();
        }  
        redirect('profile');

Here original Uploaded image is cropped , you can also create new image. Just make create_thumb = true for that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.