Welcome Guest, Not a member yet? Register   Sign In
Jcrop Library Support for codeIgniter ( part II )
#1

[eluser]Agung Wahyudiono[/eluser]
I'll continue my post about jcrop library

Code:
public function add_form($forms) {

        if (is_array($forms)){

            $input = $this->form;

            foreach($forms as $key=>$val) {

                switch ($key) {

                    case 'form_input':

                    $input .= '<p>&lt;input type="text" ';    

                    foreach ($val as $k=&gt;$v){

                        $input .= $k.'="'.$v.'" ';

                    }

                    $input .= ' /></p>';

                    break;

                    

                    case 'form_textarea':

                    $input .= '<p>&lt;textarea ';    

                    foreach ($val as $k=&gt;$v){

                        if($k<>'value'){

                            $input .= $k.'="'.$v.'" ';

                        }

                    }

                    $input .= ' >'.$val['value'].'&lt;/textarea&gt;&lt;/p>';

                    break;

                    

                    case 'form_dropdown':

                    $input .= '<p><select ';

                    $input .= 'name="'.$val[0].'" >';

                    $input .= '<option selected>'.$val[2].'</option>';

                    foreach( $val[1] as $k=>$v ){

                        $input .= '<option value="'.$k.'">'.$v.'</option>';

                    }

                    $input .= '</select></p>';

                    break;

                }

            }

        } else {

            $input = '';

        }

        $this->form = $input;

    }

    

    public function show_form($action,$option = FALSE) {

        

        if ($option == TRUE) {

            $enctype = '';

            $input = '

                &lt;input type="hidden" id="x" name="'.$this-&gt;prefix.'x" />

                &lt;input type="hidden" id="y" name="'.$this-&gt;prefix.'y" />

                &lt;input type="hidden" id="w" name="'.$this-&gt;prefix.'w" />

                &lt;input type="hidden" id="h" name="'.$this-&gt;prefix.'h" />    

            ';

            $input .= $this->form;

            $input .= '&lt;input type="submit" id="'.$this-&gt;prefix.'save" name="'.$this->prefix.'save" value="Save Croped Image!" />';

            $input.= '&lt;input type="submit" id="'.$this-&gt;prefix.'cancel" name="'.$this->prefix.'cancel" value="Cancel" />';

        } else {

            $enctype = ' enctype="multipart/form-data" ';

            $input = '&lt;input type="file" name="'.$this-&gt;prefix.'picture" size="40"/><br /><br />';

            $input.= '&lt;input type="submit" name="'.$this-&gt;prefix.'submit" value="upload"/>';

        }

        $form  = '&lt;form method="POST" action="'.$action.'" class="jNice" '.$enctype.'&gt;&lt;fieldset>';

        $form .= $input;

        $form .= '</fieldset>&lt;/form&gt;';

        return $form;

    }

    

    public function produce(& $pic_loc='',& $pic_path='',& $thumb_loc='',& $thumb_path='') {

        $x = $this->CI->input->post($this->prefix.'x') ;

        $y = $this->CI->input->post($this->prefix.'y');

        $width = $this->CI->input->post($this->prefix.'w');

        $height = $this->CI->input->post($this->prefix.'h');

        

        $pic_loc = base_url().$this->folder.$this->CI->session->userdata($this->prefix.'orig_name');

        $pic_path = $this->CI->session->userdata($this->prefix.'full_path');

        $src = imagecreatefromjpeg($this->folder.$this->CI->session->userdata($this->prefix.'orig_name'));

        $tmp = imagecreatetruecolor($this->target_w, $this->target_h);

        imagecopyresampled($tmp, $src, 0,0,$x,$y,$this->target_w,$this->target_h,$width,$height);

        if($this->create_thumb == TRUE){

            imagejpeg($tmp,$this->thumb_folder.'thumb_'.$this->CI->session->userdata($this->prefix.'orig_name'),100);

            $thumb_loc = base_url().$this->thumb_folder.'thumb_'.$this->CI->session->userdata($this->prefix.'orig_name');

            $thumb_path = $this->thumb_folder.'thumb_'.$this->CI->session->userdata($this->prefix.'orig_name');

        }else{

            imagejpeg($tmp,$this->folder.$this->CI->session->userdata($this->prefix.'orig_name'),100);

        }

        imagedestroy($tmp);

        imagedestroy($src);

        

        $this->end_session();

    }

    

    private function end_session() {

        $this->CI->session->unset_userdata(

            $this->prefix.'uploaded',$this->prefix.'file_name',$this->prefix.'file_type',

            $this->prefix.'file_path',$this->prefix.'full_path',$this->prefix.'raw_name',

            $this->prefix.'orig_name',$this->prefix.'file_ext',$this->prefix.'file_size',

            $this->prefix.'is_image',$this->prefix.'image_width',$this->prefix.'image_height',

            $this->prefix.'image_type',$this->prefix.'image_size_str'

        );

    }

    

}

?&gt;

With this library we could add som input text as we need. Before we store our data into a database. This library use the CI function except the process resizing and producing image as result. because when i use the CI functionm, I get the bed proportion of image.

This Library has many weaknes ,
eg. on the producing form , we cannot produce same field type on one form type
so i need contribution from from you all.
on next section i will show you how to implementing this library on controller




Theme © iAndrew 2016 - Forum software by © MyBB