我尝试使用codeigniter的库函数裁剪图像。但$ this-> image_lib-> crop()函数无法更改图像。
这是我的代码 -
<?php
class Cropimg extends CI_Controller {
function index()
{
$config['image_library'] = 'gd2';
$config['source_image'] = 'C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg';
$config['x_axis'] = '300';
$config['y_axis'] = '200';
$config['maintain_ratio'] = FALSE;
$config['new_image'] = 'C:\Users\Public\Pictures\Sample Pictures\new_crop_img.jpg';
// $config['width'] = $width-10;
//$config['height'] = $height-10;
$this->load->library('image_lib', $config);
if ( ! $this->image_lib->crop())
echo $this->image_lib->display_errors();
else
echo "<strong>Your image has been cropped successfully..!!</strong>";
}
}
&GT;
答案 0 :(得分:0)
请尝试此代码,其工作正常。 裁剪时是否有任何错误?
$config['image_library'] = 'GD2';
$config['source_image'] = 'C:\Users\Public\Pictures\Sample Pictures\Chrysanthemum.jpg';
$config['new_image'] = 'C:\Users\Public\Pictures\Sample Pictures\new_crop_img.jpg';
$config['height'] = '200';
$config['width'] = '300';
$config['maintain_ratio'] = FALSE;
$this->image_lib->initialize($config);
if ( ! $this->image_lib->crop())
{
echo $this->image_lib->display_errors();
}else
{
echo "<strong>Your image has been cropped successfully..!!</strong>";
}
答案 1 :(得分:0)
为此提供高度和宽度。 高度和高度宽度是必要的,从一个点(X轴,Y轴)告诉图像的长度到右侧&amp;朝向下行的长度(作为高度)。这些将被视为身高&amp;该图像的宽度。
所以取消评论
$config['height'] = '200';
$config['width'] = '300';