0

我只需要根据宽度而不是高度来调整图像的大小:(因为我使用的是** $config['maintain_ratio'] = TRUE;**,codeigniter会自动解决它(这就是问题)有时我会得到一个黑色实心作为额外的宽度或高度,

我查看了与 codegniter 的图像库相关的所有问题,但找不到与我的问题相关的任何问题:(

这是对最终结果的描述... 我只需要根据宽度调整大小,而不是高度:(

上传后我有这个...

$this->load->library('md_image');
        $source='assets/img/hotellist/'.$data1['hotel_pictures'];
        $width=746;
        $height=400;
        $dest = FALSE;
        //$this->md_image->resize_image($source, $width, $height, $source);
            $config['image_library'] = 'gd2';//imagemagik
            $config['source_image'] = 'assets/img/hotellist/'.$data1['hotel_pictures'];
            //$config['image_library'] = 'imagemagick';
            //$config['library_path'] = '/usr/X11R6/bin/';
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = TRUE;
            $config['width']     = 746;
            $config['height']   = 400;
            $config['quality']   = 75;
            $config['encrypt_name'] = TRUE;
            $config['remove_spaces'] = TRUE;
            //$config['x_axis'] = 100;
            //$config['y_axis'] = 300;
            $img =$config['source_image'];
            //var_dump('check problem',$config['source_image']);

            $this->load->library('image_lib', $config);

            $this->image_lib->resize();

然后我负责裁剪部分

$new_img =$this->md_image->crop_to_ratio($source, $width, $height, $x = 17, $y = 9, $dest = FALSE);

总而言之,有人上传了一张图片,它只根据宽度调整大小, 第1步 然后被裁剪第2步

PS:以防有人需要它md_image

4

2 回答 2

2
$this->load->library('md_image');
        $source='assets/img/hotellist/'.$data1['hotel_pictures'];
        $width=746;
        $height=400;
        $size = getimagesize($source);
        $resize_height=($size[1]*746)/$size[0];
        $dest = FALSE;
        //$this->md_image->resize_image($source, $width, $height, $source);
            $config['image_library'] = 'gd2';//imagemagik
            $config['source_image'] = 'assets/img/hotellist/'.$data1['hotel_pictures'];
            //$config['image_library'] = 'imagemagick';
            //$config['library_path'] = '/usr/X11R6/bin/';
            $config['create_thumb'] = FALSE;
            $config['maintain_ratio'] = TRUE;
            $config['width']     = 746;
            $config['height']   = $resize_height;
            $config['quality']   = 75;
            $config['encrypt_name'] = TRUE;
            $config['remove_spaces'] = TRUE;
            //$config['x_axis'] = 100;
            //$config['y_axis'] = 300;
            $img =$config['source_image'];
            //var_dump('check problem',$config['source_image']);

            $this->load->library('image_lib', $config);

            $this->image_lib->resize();
于 2014-05-15T16:21:52.130 回答
1
function resize_than_crop($path, $new_path, $width = 400, $height = 746) {

    $this->load->library('image_lib');

    $this->image_lib->initialize(array(
        'image_library' => 'gd2',
        'source_image' => $path,
        'new_image' => $new_path,
        'maintain_ratio' => true,
        'master_dim' => 'width',
        'width' => $width
    ));
    $this->image_lib->resize();

    $this->image_lib->clear();

    $this->image_lib->initialize(array(
        'image_library' => 'gd2',
        'source_image' => $new_path,
        'height' => $height
    ));
    $this->image_lib->crop();
}
于 2015-10-15T10:16:50.517 回答