0

我在 ubuntu 32 位中使用 laravel 4.2 图像干预。它正在工作,但图像未针对指定高度调整大小。假设我正在尝试调整 to 的图像大小width=800, height=600width=250, height=250但它正在调整到width=250, height=188.

我在控制器中使用了以下代码。

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

1 回答 1

0

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

function($constraint) {
    $constraint->aspectRatio();
}
于 2015-12-10T09:18:41.730 回答