gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 10:39:42 24 4
gpt4 key购买 nike

我想使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com