我在localhost上使用codeigniter 3.1。
我正在尝试裁剪图像,但裁剪不起作用。只调整工作大小。所以我启用了Gd2
php扩展。
1
public function do_crop($filename)
{
$this->load->library('image_lib');
$source_path = 'uploads/' . $filename;
$target_path = 'uploads/thumb/'.$filename;
$config = array(
'image_library' => 'gd2',
'source_image' => $source_path,
'new_image' => $target_path,
'maintain_ratio' => FALSE,
'x_axis' => 300,
'y_axis' => 100,
);
$this->image_lib->initialize($config);
}
图片尺寸= 1000X700
输出结果与原始图像尺寸1000X700
2
public function do_crop($filename)
{
$this->load->library('image_lib');
$source_path = 'uploads/' . $filename;
$target_path = 'uploads/thumb/'.$filename;
$config = array(
'image_library' => 'gd2',
'source_image' => $source_path,
'new_image' => $target_path,
'maintain_ratio' => FALSE,
'width' => 300,
'height' => 300,
'x_axis' => 350,
'y_axis' => 50
);
$this->image_lib->initialize($config);
}
图片尺寸= 1000X700
第二个示例仅调整图像大小(300x300
)但未裁剪。
答案 0 :(得分:1)
$config = array(
'source_image' => $upload_path.$image_data['file_name'],
'maintain_ratio' => FALSE,
'width' => 220,
'height' => 150,
'x_axis' => 350,
'y_axis' => 50
);
$this->image_lib->clear();
$this->image_lib->initialize($config);
$this->image_lib->crop();
详情请致See Here 详情Check Here