I'm using codeigniter and i want to resize image from user that upload via url.
Here is my code:
//upload via url
$url = $this->input->post('photo');
/* Extract the filename */
$filename = substr($url, strrpos($url, '/') + 1);
/* Save file wherever you want */
file_put_contents('myuploads/'.$filename, file_get_contents($url));
//resize start
$config['image_library'] = 'gd2';
$config['source_image'] = $filename;
$config['overwrite'] = TRUE;
$config['width'] = 59;
$config['height'] = 90;
$this->load->library('image_lib', $config);
$this->image_lib->initialize($config);
$this->image_lib->resize();
$data=array(
'username'=>$this->input->post('username'),
'deskrip'=>$this->input->post('deskrip'),
'photo'=>$filename
);
$this->db->where('id',$id);
$outp = $this->db->update('user',$data);
Upload is working but the problem is the image won't resize into 59x90 and still in original size.
Any answer?
Many thanks..
resize() method is working or not you can see error by :
if ( ! $this->image_lib->resize())
{
echo $this->image_lib->display_errors();
}
see Documentation There is a nice tutorial of image Manipulation ,from tutsplus
Hope this help you.
Thanks
Might be a bit off-topic (not through codeigniter), but I found this method to be a little easier in my project.
I used this logic to do a cropping logic for pictures.
$value = "picture.jpg";
$x = $p[0];
$y = $p[1];
$w = $p[2];
$h = $p[3];
$targ_w = $w;
$targ_h = $h;
$jpeg_quality = 90;
$src = REAL_PATH."uploads/".$value;
$src_end = $path."/".$value;
$ext = pathinfo($src, PATHINFO_EXTENSION);
if(($ext == "jpg" || $ext == "jpeg") && isset($x) && isset($y) && isset($w))
{
$img_r = imagecreatefromjpeg($src);
$dst_r = ImageCreateTrueColor( $targ_w, $targ_h );
imagecopyresampled($dst_r,$img_r,0,0,$x,$y,
$targ_w,$targ_h,$w,$h);
unlink($src);
imagejpeg($dst_r,$src_end,$jpeg_quality);
}