鉴于以下代码:
$car= new Car();
$car->name = Input::get('name');
$car->photo = Input::file('photo');
$car->save();
我需要在保存之前裁剪照片(带偏移量)。我尝试使用 ImageResizer插件,但无法弄清楚如何将其 API 与上述代码集成。
最佳答案
是的,您可以 resize image
使用该 plugin
但你甚至不需要它,因为它在内部也使用 OctoberCMS built-in Resize function
.
首先,您需要将其保存在磁盘上,然后就地调整其大小。
for this you can use October Cms's in-built
Resizer
https://octobercms.com/docs/api/october/rain/database/attach/resizer
如果您只需要阅读 ,您也可以裁剪图像https://octobercms.com/docs/api/october/rain/database/attach/resizer#crop博士,你很高兴去。 如果您需要,还有更多选择。
<?php namespace hardiksatasiya/...somethig;
use October\Rain\Database\Attach\Resizer;
// ...
$car= new Car();
$car->name = Input::get('name');
$car->photo = Input::file('photo');
$car->save();
// code to resize image
$width = 100;
$height = 100;
$options = []; // or ['mode' => 'crop']
Resizer::open($car->photo->getLocalPath()) // create from real path
->resize($width, $height, $options)
->save($car->photo->getLocalPath());
此代码将打开保存的图像,调整其大小并将其保存在同一位置。
如果您遇到任何问题,请发表评论。
关于laravel - OctoberCMS:上传时裁剪原始图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50080209/