根据宽度调整图片大小&裁剪额外高度,代码指示符 [英] Resize image according to width only & crop Extra Height , Codeigniter

查看:175
本文介绍了根据宽度调整图片大小&裁剪额外高度,代码指示符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据宽度,而不是高度调整我的图片大小:(
,因为我使用** $ config ['maintain_ratio'] = TRUE ; **
,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 ,

我已经看过所有的有关codegniter的图像
库的问题,我找不到任何与我的问题相关的问题:(

i have looked at all of the questions relating to codegniter's image library and i couldn't find anything related to my problem :(

这是对最终结果的描述...

Here is a description on the final result...

上传此文件后...

$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 and then it gets cropped

PS:incase有人需要它 md_image

PS: incase someone needed it 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();

这篇关于根据宽度调整图片大小&裁剪额外高度,代码指示符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆