本文介绍了Codeigniter图像裁剪不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在localhost上使用codeigniter 3.1。
我试图裁剪图像,但裁剪不工作。只调整工作大小。所以我启用了 Gd2
php扩展。
1。
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 b
$ b
输出结果与原始图像大小相同 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 b
$ b
第二个示例只调整图片大小( 300x300
),但未剪裁。
解决方案
$ 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();
详情请
更多信息
I am using codeigniter 3.1 on localhost.I am trying to crop images but cropping is not working. Only resize working. So i enabled Gd2
php extension.
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);
}
Image size = 1000X700
The output result is same as original image size 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);
}
Image size = 1000X700
And the 2nd example only resize (300x300
) the image but not cropped.
解决方案
$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();
For more details Please See HereFor More Info Check Here
这篇关于Codeigniter图像裁剪不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!