[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><input type="text" ';
foreach ($val as $k=>$v){
$input .= $k.'="'.$v.'" ';
}
$input .= ' /></p>';
break;
case 'form_textarea':
$input .= '<p><textarea ';
foreach ($val as $k=>$v){
if($k<>'value'){
$input .= $k.'="'.$v.'" ';
}
}
$input .= ' >'.$val['value'].'</textarea></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 = '
<input type="hidden" id="x" name="'.$this->prefix.'x" />
<input type="hidden" id="y" name="'.$this->prefix.'y" />
<input type="hidden" id="w" name="'.$this->prefix.'w" />
<input type="hidden" id="h" name="'.$this->prefix.'h" />
';
$input .= $this->form;
$input .= '<input type="submit" id="'.$this->prefix.'save" name="'.$this->prefix.'save" value="Save Croped Image!" />';
$input.= '<input type="submit" id="'.$this->prefix.'cancel" name="'.$this->prefix.'cancel" value="Cancel" />';
} else {
$enctype = ' enctype="multipart/form-data" ';
$input = '<input type="file" name="'.$this->prefix.'picture" size="40"/><br /><br />';
$input.= '<input type="submit" name="'.$this->prefix.'submit" value="upload"/>';
}
$form = '<form method="POST" action="'.$action.'" class="jNice" '.$enctype.'><fieldset>';
$form .= $input;
$form .= '</fieldset></form>';
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'
);
}
}
?>
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