0

我试图通过使用 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>";
}
   }

?>

4

2 回答 2

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>";
    }
于 2013-10-28T07:19:10.613 回答
0

为此提供高度和宽度。高度和宽度是必要的,以从一个点(X 轴,Y 轴)告诉右侧的图像长度是多少,向下的长度(作为高度)是多少。这些将被视为该图像的高度和宽度。

所以取消评论

 $config['height'] = '200';
 $config['width'] = '300';
于 2013-11-19T11:00:32.587 回答