在codeigniter中调整图像大小而不失真图像

时间:2012-10-26 10:22:00

标签: php codeigniter activerecord image-processing imagelibrary

我想在没有图像失真的情况下调整图像大小。例如,如果我将图像高度设置为100,宽度设置为200.图像大小必须是100高度和200宽度。为了实现我想要的裁剪图像而不是扭曲。

我的配置选项: -

            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = FALSE;
            $config['master_dim'] = 'auto';
            $config['width'] = 100;
            $config['height']= 100;

            $this->image_lib->initialize($config);
            $this->image_lib->resize();

也可以不使用任何其他图像处理库吗?

3 个答案:

答案 0 :(得分:1)

 $this->image_lib->resize();

我认为一定是

 $this->image_lib->crop();

答案 1 :(得分:1)

你可以像有人在这里说的那样调整大小或裁剪它。

如果CROP

$config['image_library'] = 'imagemagick';
$config['library_path'] = '/usr/X11R6/bin/';
$config['source_image'] = '/path/to/image/mypic.jpg';
$config['x_axis'] = '100';
$config['y_axis'] = '60';
$this->image_lib->initialize($config); 

if ( ! $this->image_lib->crop())
{
   echo $this->image_lib->display_errors();
}

如果调整大小正是您所拥有的。

答案 2 :(得分:1)

我已经解决了我的问题。我不得不重新调整我的图像大小然后裁剪它。如果你有一个比这更好的建议,它有点漫长的过程。

我的代码:

            //Resize Image
            $config = array();
            $config['image_library'] = 'gd2';
            $config['source_image'] = './assets/original/'.$image_name;
            $config['new_image'] = './assets/banner/'.$image_name;
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = TRUE;
            $config['master_dim']= 'width';
            $config['quality']  = '100';
            $config['width'] = 1260;
            $config['height']= 645;
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            // Crop Image
            $config = array();
            $config['image_library'] = 'gd2';
            $config['source_image'] = './assets/banner/'.$image_name;
            $config['new_image'] = './assets/banner/'.$image_name;
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = FALSE;
            $config['quality']  = '100';
            $config['x_axis'] = 0;
            $config['y_axis'] = 0;
            $config['width'] = 1260;
            $config['height']= 645;
            $this->image_lib->initialize($config);
            $this->image_lib->crop();