dousao8152 2014-03-25 15:21
浏览 59
已采纳

仅根据宽度调整图像大小并裁剪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 ,

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... I need to resize according to width only , not height :(

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 Step 1 and then it gets cropped Step 2

PS: incase someone needed it md_image

  • 写回答

2条回答 默认 最新

  • doulong4169 2014-05-15 16:21
    关注
    $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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么