【发布时间】:2019-11-20 06:32:19
【问题描述】:
我正在做一个 symfony 项目,我正在使用 vichuploader 和 liipImagine,所以我想调整上传图片的大小并将其(调整后的图片)保存在上传目录中,以便用户上传图片到 10Mb,然后调整它的大小以保持 100 KB 的大小。
到目前为止,我发现使用imagine_filter 来调整上传图像的大小,但在这种情况下,它会保留原始图像,并且在缓存中创建调整大小的图像。
所以我试图做这样的事情: 在我的控制器中
public function edit(Post $post,Request $request)
{
$form = $this->createForm(PostType::class, $post);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->flush();
// And then resize all uploaded images...
// All i know is to get the filename of each image stored in public/media/posts.
// In loop because we allow multiple upload
// foreach ($post->getPictures() as $picture) {
// $picture->getFilename();
// }
$this->addFlash('success', 'ELement successfully modified');
return $this->redirectToRoute('admin.post.index');
}
return $this->render('admin/post/edit.html.twig', [
'post' => $post,
'form' => $form->createView()
]);
}
我的帖子类型
class PostType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('category', EntityType::class, [
'class' => Category::class,
'required' => true,
'choice_label' => 'title'
])
->add('pictureFiles', FileType::class, [
'required' => false,
'multiple' => true
])
->add('content')
;
}
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Post::class,
]);
}
}
感谢您的帮助!
【问题讨论】:
标签: symfony vichuploaderbundle liipimaginebundle