LiipImagineBundle:如何在控制器中应用过滤器?

hum*_*pdi 4 symfony liipimaginebundle

我想使用LiipImagineBundle调整我在控制器中上传的图片的大小.

  $extension = $file->guessExtension();
  $newfilename = sha1(uniqid(mt_rand(), true));
  $tmp_folder = $this->get('kernel')->getRootDir() . '/../web/uploads/tmp/'; // folder to store unfiltered temp file
  $tmp_imagename = $newfilename.'.'.$extension;
  $file->move($tmp_folder, $tmp_imagename);

  $tmpImagePathRel = '/uploads/tmp/' . $tmp_imagename;
  $processedImage = $this->container->get('liip_imagine.data.manager')->find('profilepic', $tmpImagePathRel);
  $newimage_string = $this->container->get('liip_imagine.filter.manager')->get($request, 'profilepic', $processedImage, $tmpImagePathRel)->getContent();

  unlink($tmp_folder . $tmp_imagename); // eliminate unfiltered temp file.
  $perm_folder = $this->get('kernel')->getRootDir() . '/../web/uploads/userimages/';
  $perm_imagepath = $perm_folder . $newfilename . '.jpeg';
  $f = fopen($perm_imagepathh, 'w');
  fwrite($f, $newimage_string); 
  fclose($f);
Run Code Online (Sandbox Code Playgroud)

这带来了以下错误:

Attempted to call method "get" on class "Liip\ImagineBundle\Imagine\Filter\FilterManager" in C:\...\UserController.php line xx. Did you mean to call: "getFilterConfiguration"?
Run Code Online (Sandbox Code Playgroud)

然后我尝试了

$newimage_string = $this->container->get('liip_imagine.filter.manager')->getFilterConfiguration($request, 'profilepic', $processedImage, $tmpImagePathRel);
Run Code Online (Sandbox Code Playgroud)

它带给我的是

Warning: fwrite() expects parameter 2 to be string, object given in C:\..
Run Code Online (Sandbox Code Playgroud)

我几乎找不到任何文档或示例来完成这项任务:(我对包文档非常失望://

任何帮助真的很感激!

提前致谢!

hum*_*pdi 9

好吧,我让它工作,也许对其他人有用:

$newimage_string = $this->container->get('liip_imagine.filter.manager')->applyFilter($processedImage, 'profilepic')->getContent();
Run Code Online (Sandbox Code Playgroud)