CodeIgniter image cropping - image not affected by crop() parameters
I have this model to crop the user's image
function crop_avatar()
{
$id = $this->tank_auth->get_user_id();
//get current avatar
$query = $this->db->get_where('user_profiles', array('id' => $id));
foreach ($query->result() as $row) {
$j[$row->avatar] = $row->avatar;
}
$config['image_library'] = 'gd';
$config['source_image'] = '.' . substr("$row->avatar", 18);
$config['x_axis'] = '10';
$config['y_axis']开发者_如何转开发 = '60';
$this->load->library('image_lib');
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}
// print_r($config);
}
which generates this array (via print_r)
Array
(
[image_library] => gd
[source_image] => ./images/avatars/b0b623057.jpg
[x_axis] => 10
[y_axis] => 60
)
For some reason unknown to me - there's no cropping going on. The original image passes straight thru this model, and is unchanged.
I do have GD on my server -- any ideas what might be wrong here?
Thanks a ton.
You need to define the width and height you want your image to be cropped at.
The x_axis
and y_axis
config values are the point in your existing image where the crop should start.
To put it another way, you need 4 measurements to crop the image : where to start vertically (y_axis
), where to start horizontally (x_axis
), where to end vertically (height
) and where to end horizontally (width
)
If one of the dimensions of your cropped image is the same as that of your original image, don't forget to set maintain_ratio
to false
精彩评论