我有以下内容:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Imagine\Image\Box;
use Imagine\Image\ImageInterface;
use Imagine;
class UploadController extends Controller {
public function processImage($request) {
$file = $request->file('file');
$path = '/images';
$fileName = 'image.png';
if ($file) {
$file->move('../public' . $path, $fileName);
$gThumb = $this->createThumbnail(219, 300, '../public/images', 'image', 'png', 'thumb', true);
$pThumb = $this->createThumbnail(300, 300, '../public/images', 'image', 'png', 'pthumb');
return response()->json([
'gallery_thumbnail' => $path . '/' . $gThumb,
'upload_thumbnail' => $path . '/' . $pThumb
]);
}
}
function createThumbnail($height, $width, $path, $filename, $extension, $postfix = null, $mask = null)
{
$mode = ImageInterface::THUMBNAIL_OUTBOUND;
$size = new Box($width, $height);
$postfix = $postfix ? $postfix : 'thumb';
$thumbnail = Imagine::open("{$path}/{$filename}.{$extension}")->thumbnail($size, $mode);
if ($mask) {
$mask = Imagine::open('../public/images/masks/bubble-splash.png');
$thumbnail->applyMask($mask);
}
$destination = "{$filename}" . "." . $postfix . "." . "{$extension}";
$thumbnail->save("{$path}/{$destination}");
return $destination;
}
}
它将图像按预期保存,但不会将蒙版应用于缩略图。
我错在哪里了(我正在使用Laravel 5)?
此外,当脚本运行时,它需要大约1分钟才能完成,因此它正在做某些事情,但是输出的图像仍然没有应用蒙版。
最终,我想使用这些人 https://www.imgix.com/
createThumbnail()
函数的$mask
参数中传递了一个真值吗? - Ben Claar$mask = Imagine::open(__DIR__ . '/../public/images/masks/bubble-splash.png');
。 - Pedro Cordeiro