简体   繁体   English

仅根据宽度调整图像大小并裁切Extra Height,Codeigniter

[英]Resize image according to width only & crop Extra Height , Codeigniter

I need to resize my images according to width only , not height :( since i am using ** $config['maintain_ratio'] = TRUE; ** , codeigniter solves it automatically (thats the problem) sometimes i get a black solid as an extra width or height , 我只需要根据宽度而不是高度来调整图像大小:(因为我使用的是** $config['maintain_ratio'] = TRUE; **,codeigniter会自动解决它(这就是问题),有时我会得到黑色固体额外的宽度或高度,

i have looked at all of the questions relating to codegniter's image library and i couldn't find anything related to my problem :( 我看了所有与codegniter图片库有关的问题,但找不到与我的问题有关的任何东西:(

Here is a description on the final result... 这是最终结果的描述... 我只需要根据宽度而不是高度来调整大小:(

After uploading am having this ... 上传后有这个...

$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();

Then i am take caring of the cropping part 然后我要照顾好种植部分

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

to sum up , Someone uploads an image , it gets resized to according to width only 总结一下, 有人上传图片 ,仅根据宽度调整大小 第1步 and then it gets cropped 然后被裁剪 第2步

PS: incase someone needed it md_image PS:万一有人需要md_image

$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();
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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM