dongpu3792 2015-12-10 08:05
浏览 58

laravel 4.2图像干预没有针对指定高度正确调整尺寸

I'm using laravel 4.2 image intervention in ubuntu 32 bit. It's working, but image is not resizing for the specified height. Suppose I'm trying to resize image of width=800, height=600 to width=250, height=250 but it is resizing to width=250, height=188 .

I used the following code in my controller.

$imageType = array(
  'detail_page' => array(
  'width' => 250,
  'height' => 250      
  ),
);

$file = Input::file('album_image');

if($file->isValid()) {

    $file_name = microtime();
    $file_name = str_replace(' ', '_', $file_name);
    $file_name = str_replace('.', '_', $file_name);
    $file_name = $file_name . '.' . $file->getClientOriginalExtension();
    $file->move(public_path() . '/album_uploads/', $file_name);

    foreach ($imageType as $key => $value) {

      $file = Image::make(sprintf('album_uploads/%s',$file_name))->resize($value['width'], $value['height'],

        function($constraint) {
          $constraint->aspectRatio();
      });

      $file->save(public_path().'/album_uploads/'.$value['width'].'X'.$value['height'].'/'. $file_name);

    }

   $album_image_url = URL::to('album_uploads/' . $file_name);
}
  • 写回答

1条回答 默认 最新

  • doulou1970 2015-12-10 09:18
    关注

    Remove your aspect ratio constraint: 800x600 -> 250x188 -> 4x3

    function($constraint) {
        $constraint->aspectRatio();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2024-五一综合模拟赛
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭