OctoberCMS:在上传时裁剪原始图像

问题描述 投票:3回答:1

给出以下代码:

$car= new Car();
$car->name = Input::get('name');
$car->photo = Input::file('photo');
$car->save();

我需要在保存之前裁剪照片(带偏移)。我尝试使用ImageResizer插件,但无法弄清楚如何将其API与上面的代码集成。任何意见,将不胜感激。

laravel image-resizing octobercms
1个回答
2
投票

是的你可以resize image使用那个plugin但你甚至不需要它在内部它也使用OctoberCMS built-in Resize function

首先,您需要将其保存在磁盘上,然后就地调整大小。

为此你可以使用October Cms的内置Resizer https://octobercms.com/docs/api/october/rain/database/attach/resizer

如果你只需要阅读https://octobercms.com/docs/api/october/rain/database/attach/resizer#crop doc,你也可以裁剪图像,你很高兴。如果您需要,还有更多选择。

<?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());

此代码将打开已保存的图像,调整其大小并将其保存在同一位置。

如果您有任何问题请评论。

© www.soinside.com 2019 - 2024. All rights reserved.