I have an image trimmer in my project in CodeIgniter that visits images like picresize.com (I use jCrop ). It works fine with the vanilla code below:
<?php $save_to = $this->config->item('images_gallery_thumb_folder').$data['photo_image']; $targ_w = $this->config->item('gallery_thumb_width'); $targ_h = $this->config->item('gallery_thumb_height'); $src = $this->config->item('images_gallery_folder').$data['photo_image']; $types = array(1 => 'gif', 'jpeg', 'png'); list($width,$height,$type) = getimagesize($src); switch ($types[$type]) { case 'jpeg': $img_r = imagecreatefromjpeg($src); break; case 'gif': $img_r = imagecreatefromgif($src); break; case 'png': $img_r = imagecreatefrompng($src); break; default: $img_r = imagecreatefromjpeg($src); break; } $dst_r = ImageCreateTrueColor($targ_w,$targ_h ); imagecopyresampled($dst_r,$img_r,0,0,$_POST['x'],$_POST['y'], $targ_w,$targ_h,$_POST['w'],$_POST['h']); switch ($types[$type]) { case 'jpeg': imagejpeg($dst_r, $save_to, 90);
But I want to do this with CodeIgniter.
This is what I came up with:
<?php $img_config = array( 'source_image' => $src, 'new_image' => $save_to, 'maintain_ratio' => false, 'width' => $targ_w, 'height' => $targ_h, 'x_axis' => $_POST['x'], 'y_axis' => $_POST['y'] ); $this->load->library('image_lib',$img_config);
The fact is that it drops from a position, but it does not change (I think that I have established a large yield area). This is only a crop from this position.
I also use image_moo in the project, but I also failed.
Edit: In Image_moo, here is the code I've come to so far:
$this->image_moo ->load($src) ->crop($_POST['x'],$_POST['y'],($_POST['x']+$_POST['w']),($_POST['y']+$_POST['h'])) ->resize($targ_w,$targ_h) ->save($save_to,true);
The fact is that when I use the resize parameter, it completely ignores the cropping line and resizes the whole image. If I resized before and later call the crop, it just fails. I can overcome this with two image_moo calls that I would not want.
This also does not work:
$this->image_moo ->load($src) ->crop($_POST['x'],$_POST['y'],($_POST['x']+$_POST['w']),($_POST['y']+$_POST['h'])) //->resize($targ_w,$targ_h) ->save($save_to,true) ->resize($targ_w,$targ_h) ->save($save_to,true);
For example: this way it works:
$this->image_moo ->load($src) ->crop($_POST['x'],$_POST['y'],($_POST['x']+$_POST['w']),($_POST['y']+$_POST['h'])) //->resize($targ_w,$targ_h) ->save($save_to,true); $this->image_moo ->load($save_to) ->resize($targ_w,$targ_h) ->save($save_to,true);
So, how do I resize + crop with given x / y offsets using the CodeIgniter (or image_moo) method with one call to image_moo or CI image_lib?
You should probably ask why I call him twice. Well, PQ is important, and I'm worried that calling it twice reduces image quality.
Thanks in advance,