symfony - LiipImagineBundle:如何在 Controller 中应用过滤器?

标签 symfony liipimaginebundle

我想使用 LiipImagineBundle 调整 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);

这会带来以下错误:

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

然后我尝试一下

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

它给我带来了

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

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

非常感谢任何帮助!

提前致谢!

最佳答案

好吧,我让它工作了,可能对其他人有用:

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

关于symfony - LiipImagineBundle:如何在 Controller 中应用过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25749868/

相关文章:

php - Symfony2、Liipimaginebundle 不起作用,并且不创建文件夹和图像

symfony - Sonata media Liip Imagine Integration 奏鸣曲媒体 Liip Imagine Integration

Symfony2 1 :M/1:1 Relationship and Sonata Admin Form

php - 如何使用 Symfony 表单和数据转换器实现测试隔离?

php - 在开发环境中对某些 url 使用 prod 环境

symfony - S3 Bucket Policy by domain 返回 403 Forbidden for object requests in Symfony app with Varnish

symfony - LiipImageBundle 按比例增加大小和比率

php - Symfony:针对 LDAP 服务器对用户进行身份验证,但仅当用户名位于自定义数据库表中时才允许登录

forms - 如何使用Symfony 2预选表单单选项目?

php - Symfony:持久化嵌入表单并避免重复条目