LiipImagineBundle: how to apply a filter in the controller?

I want to use LiipImagineBundle to resize uploaded images in the controller.

  $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);

This results in the following error:

Attempted to call method "get" on class "Liip\ImagineBundle\Imagine\Filter\FilterManager" in C:\...\UserController.php line xx. Did you mean to call: "getFilterConfiguration"?

Then I will try instead

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

And it brings me

Warning: fwrite() expects parameter 2 to be string, object given in C:\..

I can hardly find any documentation or examples to accomplish this task :( Im pretty disappointed with the documentation bundle: //

Any help really appreciated!

Thanks in advance!

+4
source share
1 answer

Ok, I earned it, perhaps useful for others:

$newimage_string = $this->container->get('liip_imagine.filter.manager')->applyFilter($processedImage, 'profilepic')->getContent();
+9
source

All Articles