Bla*_*ack 6 php image-manipulation laravel
我想用自定义比例调整图像大小 (width:height)=(5:1)
使用干预的图像处理库在laravel.
如果图像拉伸,这不是问题.我不想把任何固定的高度或宽度.
所以请给我一些建议.
我认为最好的解决方案可能是使用库中的fit().
像这样:
// open 4/3 image for example
$image = Image::make('foo.jpg');
// your desired ratio
$ratio = 16/9;
// resize
$image->fit($image->width(), intval($image->width() / $ratio));
Run Code Online (Sandbox Code Playgroud)
它不会拉伸图像.
我认为干预图像库的调整大小功能中没有此选项。您可以使用getimagesize()php 函数获取高度和宽度,并将宽度除以 5(在您的情况下为 5,因为您想要 5:1)来获取高度。
$image=getimagesize($image_file);
$width=$image[0]; // $image[0] is the width
$height=$image[0]/5; // $image[1] is the height
Run Code Online (Sandbox Code Playgroud)
您可以使用干预resize()功能来调整大小到该高度和宽度。
Image::make($source_image)
->resize($width,$height ,false,false)
->save($destination);`
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13174 次 |
| 最近记录: |